A Rust procedural macro crate that provides logging utilities for HTTP request handlers.
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.
- 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
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()
}The macro transforms your function to include logging statements:
- Before execution: Logs
"Executing Endpoint: {function_name}" - After execution: Logs
"{status_code}: Endpoint {function_name}"
INFO: Executing Endpoint: my_endpoint
INFO: 200 OK: Endpoint my_endpoint
syn(v2.0): For parsing Rust syntaxquote(v1.0): For generating Rust codeproc-macro: Standard library for procedural macros
This crate is a procedural macro library (proc-macro = true) that operates at
compile time to transform your functions. It:
- Parses the input function using
syn - Extracts the function name, inputs, and body
- Wraps the original function body with logging statements
- Returns the modified function using
quote!
- Rust 2021 Edition
- Functions must be
asyncand return aResponsetype - Requires a logging framework (like
log,tracing, etc.) to be configured in your application
To test the macro:
cargo testTo see the expanded macro output:
cargo expand