Access log.

This commit is contained in:
Tom Alexander 2024-07-14 15:50:13 -04:00
parent 25c06cbffd
commit 8fb5a83e86
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 29 additions and 1 deletions

24
Cargo.lock generated
View File

@ -110,6 +110,12 @@ dependencies = [
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "bytes"
version = "1.6.1"
@ -711,6 +717,23 @@ dependencies = [
"tower-service",
]
[[package]]
name = "tower-http"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
dependencies = [
"bitflags",
"bytes",
"http",
"http-body",
"http-body-util",
"pin-project-lite",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-layer"
version = "0.3.2"
@ -809,6 +832,7 @@ dependencies = [
"axum",
"serde",
"tokio",
"tower-http",
"tracing",
"tracing-subscriber",
]

View File

@ -22,6 +22,7 @@ include = [
axum = { version = "0.7.5", default-features = false, features = ["tokio", "http1", "http2", "json"] }
serde = { version = "1.0.204", features = ["derive"] }
tokio = { version = "1.38.0", default-features = false, features = ["macros", "process", "rt", "rt-multi-thread"] }
tower-http = { version = "0.5.2", default-features = false, features = ["trace"] }
# default attributes, std, tracing-attributes
tracing = { version = "0.1.40", default-features = false, features = ["attributes", "std", "tracing-attributes", "async-await"] }
# default alloc, ansi, fmt, nu-ansi-term, registry, sharded-slab, smallvec, std, thread_local, tracing-log

View File

@ -3,6 +3,7 @@ use axum::routing::get;
use axum::Json;
use axum::Router;
use serde::Serialize;
use tower_http::trace::TraceLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
@ -16,7 +17,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.with(tracing_subscriber::fmt::layer())
.init();
let app = Router::new().route("/health", get(health));
let app = Router::new()
.route("/health", get(health))
.layer(TraceLayer::new_for_http());
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
tracing::info!("listening on {}", listener.local_addr().unwrap());