From 7724c54b4bd8edc9c9cca3e0ae1b459b4550e0fb Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 Jul 2023 01:32:31 +0300 Subject: main: use tracing_tree in debug builds This gives me much more readable traces. JSON logging is still superior in production, where logs are stored in systemd-journald and preferably need to be self-contained lines. --- kittybox-rs/Cargo.lock | 1 + kittybox-rs/Cargo.toml | 1 + kittybox-rs/src/main.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'kittybox-rs') diff --git a/kittybox-rs/Cargo.lock b/kittybox-rs/Cargo.lock index 1934da0..36a785a 100644 --- a/kittybox-rs/Cargo.lock +++ b/kittybox-rs/Cargo.lock @@ -1498,6 +1498,7 @@ dependencies = [ "tower", "tower-http", "tracing", + "tracing-log", "tracing-subscriber", "tracing-test", "tracing-tree", diff --git a/kittybox-rs/Cargo.toml b/kittybox-rs/Cargo.toml index c5aedf1..4c7670d 100644 --- a/kittybox-rs/Cargo.toml +++ b/kittybox-rs/Cargo.toml @@ -83,6 +83,7 @@ relative-path = "^1.5.0" # Portable relative paths for Rust sha2 = "^0.9.8" # SHA-2 series of algorithms for Rust tracing = { version = "0.1.34", features = [] } tracing-tree = "0.2.1" +tracing-log = "0.1.3" tracing-subscriber = { version = "0.3.11", features = ["env-filter", "json"] } tower-http = { version = "0.3.3", features = ["trace", "cors", "catch-panic"] } tower = { version = "0.4.12", features = ["tracing"] } diff --git a/kittybox-rs/src/main.rs b/kittybox-rs/src/main.rs index 3136924..68d3b01 100644 --- a/kittybox-rs/src/main.rs +++ b/kittybox-rs/src/main.rs @@ -147,10 +147,18 @@ where #[tokio::main] async fn main() { use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; + Registry::default() .with(EnvFilter::from_default_env()) - .with(tracing_subscriber::fmt::layer().json()) + //.with(tracing_subscriber::fmt::layer().json()) + .with( + #[cfg(debug_assertions)] + tracing_tree::HierarchicalLayer::new(2), + #[cfg(not(debug_assertions))] + tracing_subscriber::fmt::layer().json() + ) .init(); + //let _ = tracing_log::LogTracer::init(); info!("Starting the kittybox server..."); -- cgit 1.4.1