axum_log_util 0.1.0

A procedural macro crate for automatic logging of Axum HTTP request handlers
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 7.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 273.65 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Matze99

Axum Log Util

A Rust procedural macro crate that provides logging utilities for HTTP request handlers.

Overview

axum_log_util is a procedural macro crate designed to automatically add logging capabilities to async HTTP request handler functions. It wraps functions with logging statements that record when endpoints are executed and their response status codes.

Features

  • Automatic Request Logging: Logs when an endpoint function starts executing
  • Response Status Logging: Logs the HTTP status code when the endpoint completes
  • Async Function Support: Designed specifically for async HTTP handlers
  • Zero Configuration: Simply add the attribute macro to your functions

Usage

Add the #[log_request] attribute to your async HTTP handler functions:

use axum_log_util::log_request;

#[log_request]
pub async fn my_endpoint() -> Response {
    // Your endpoint logic here
    Response::new()
}

What it does

The macro transforms your function to include logging statements:

  1. Before execution: Logs "Executing Endpoint: {function_name}"
  2. After execution: Logs "{status_code}: Endpoint {function_name}"

Example Output

INFO: Executing Endpoint: my_endpoint
INFO: 200 OK: Endpoint my_endpoint

Dependencies

  • syn (v2.0): For parsing Rust syntax
  • quote (v1.0): For generating Rust code
  • proc-macro: Standard library for procedural macros

Technical Details

This crate is a procedural macro library (proc-macro = true) that operates at compile time to transform your functions. It:

  1. Parses the input function using syn
  2. Extracts the function name, inputs, and body
  3. Wraps the original function body with logging statements
  4. Returns the modified function using quote!

Requirements

  • Rust 2021 Edition
  • Functions must be async and return a Response type
  • Requires a logging framework (like log, tracing, etc.) to be configured in your application

Development

To test the macro:

cargo test

To see the expanded macro output:

cargo expand