2
votes

Is there a way to log all request being received by actix-web irrespective whether the endpoint exists or not? It seems I need to use middleware for this, is this the recommended approach?

Allan.

1
This is exactly what I was looking for, thank you "kmdreko". I am looking for a way to accept this answer.Allan K

1 Answers

1
votes

There is logging middleware available as part of actix_web: actix_web::middleware::Logger

Middleware for logging request and response info to the terminal. Logger middleware uses standard log crate to log information.

Middleware is called for each request (so long no other middleware or route handles it beforehand), so putting it on your App at the top level should get all requests, whether the endpoint exists or not.

let app = App::new()
    .wrap(Logger::default())
    ...