Skip to content

Commit

Permalink
feat: [torrust#468] deafult logging for API requests
Browse files Browse the repository at this point in the history
This change enables the default logging for HTTP requests to the API:

```
2024-02-12T14:15:15.546548923+00:00 [tower_http::trace::make_span][INFO] request; method=GET uri=/v1/about version=HTTP/1.1
2024-02-12T14:15:15.546840151+00:00 [tower_http::trace::on_response][INFO] finished processing request latency=0 ms status=200
2024-02-12T14:15:34.754336133+00:00 [tower_http::trace::make_span][INFO] request; method=GET uri=/v1/about/license version=HTTP/1.1
2024-02-12T14:15:34.754544571+00:00 [tower_http::trace::on_response][INFO] finished processing request latency=0 ms status=200
```
  • Loading branch information
josecelano committed Feb 12, 2024
1 parent c1e01f8 commit eb85fb9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/web/api/server/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use axum::{Json, Router};
use serde_json::{json, Value};
use tower_http::compression::CompressionLayer;
use tower_http::cors::CorsLayer;
use tower_http::trace::{self, TraceLayer};
use tracing::Level;

use super::contexts::{about, category, proxy, settings, tag, torrent, user};
use crate::bootstrap::config::ENV_VAR_CORS_PERMISSIVE;
Expand Down Expand Up @@ -46,7 +48,14 @@ pub fn router(app_data: Arc<AppData>) -> Router {
router
};

router.layer(DefaultBodyLimit::max(10_485_760)).layer(CompressionLayer::new())
router
.layer(DefaultBodyLimit::max(10_485_760))
.layer(CompressionLayer::new())
.layer(
TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(tracing::Level::INFO))
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
)
}

/// Endpoint for container health check.
Expand Down

0 comments on commit eb85fb9

Please sign in to comment.