mirror of
https://github.com/ankitects/anki.git
synced 2026-01-15 06:49:03 -05:00
* Prepare to switch Rust import style * Run nightly format Closes #2320 * Clean up a few imports * Enable comment wrapping * Wrap comments
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use std::time::Duration;
|
|
|
|
use axum::body::Body;
|
|
use axum::http::Request;
|
|
use axum::response::Response;
|
|
use axum::Router;
|
|
use tower_http::trace::TraceLayer;
|
|
use tracing::info_span;
|
|
use tracing::Span;
|
|
|
|
pub fn with_logging_layer(router: Router) -> Router {
|
|
router.layer(
|
|
TraceLayer::new_for_http()
|
|
.make_span_with(|request: &Request<Body>| {
|
|
info_span!(
|
|
"request",
|
|
uri = request.uri().path(),
|
|
ip = tracing::field::Empty,
|
|
uid = tracing::field::Empty,
|
|
client = tracing::field::Empty,
|
|
session = tracing::field::Empty,
|
|
)
|
|
})
|
|
.on_request(())
|
|
.on_response(|response: &Response, latency: Duration, _span: &Span| {
|
|
tracing::info!(
|
|
elap_ms = latency.as_millis() as u32,
|
|
httpstatus = response.status().as_u16(),
|
|
"finished"
|
|
);
|
|
})
|
|
.on_failure(()),
|
|
)
|
|
}
|