pub async fn log_request(
__arg0: ConnectInfo<SocketAddr>,
req: Request<Body>,
next: Next,
) -> Result<Response, StatusCode>
Expand description
Logs method, path, IP address, user ID (if authenticated), origin, and user-agent
for each incoming HTTP request. Automatically skips CORS preflight OPTIONS
requests.
This middleware can help trace incoming traffic, debug authentication issues, and monitor frontend usage patterns.
§Usage:
Apply this middleware globally using:
ⓘ
use axum::Router;
use axum::middleware::from_fn;
use api::auth::middleware::log_request;
let app = Router::new().layer(from_fn(log_request));
§Fields Logged:
method
: HTTP method used (GET
,POST
, etc.)path
: Requested URI pathip
: Remote IP address of the clientuser
: User ID if authenticated,0
if notorigin
: Value of theOrigin
header if presentuser_agent
: Value of theUser-Agent
header if present