From ef1448a3f5ebbd70b684298161003c1e07271ea9 Mon Sep 17 00:00:00 2001 From: Weipeng Hong <961365124@qq.com> Date: Sat, 24 Aug 2024 14:36:08 +0800 Subject: [PATCH] Use `env!("CARGO_CRATE_NAME")` in the example to simplify the tracing setup code (#2884) --- examples/chat/src/main.rs | 2 +- examples/compression/src/main.rs | 2 +- .../consume-body-in-extractor-or-middleware/src/main.rs | 2 +- examples/customize-extractor-error/src/main.rs | 2 +- examples/customize-path-rejection/src/main.rs | 2 +- examples/dependency-injection/src/main.rs | 2 +- examples/diesel-async-postgres/src/main.rs | 2 +- examples/diesel-postgres/src/main.rs | 2 +- examples/error-handling/src/main.rs | 5 +++-- examples/form/src/main.rs | 2 +- examples/global-404-handler/src/main.rs | 2 +- examples/graceful-shutdown/src/main.rs | 6 +++++- examples/http-proxy/src/main.rs | 5 +++-- examples/jwt/src/main.rs | 2 +- examples/key-value-store/src/main.rs | 5 +++-- examples/low-level-openssl/src/main.rs | 2 +- examples/low-level-rustls/src/main.rs | 2 +- examples/multipart-form/src/main.rs | 5 +++-- examples/oauth/src/main.rs | 2 +- examples/parse-body-based-on-content-type/src/main.rs | 2 +- examples/print-request-response/src/main.rs | 5 +++-- examples/prometheus-metrics/src/main.rs | 5 +++-- examples/reqwest-response/src/main.rs | 5 +++-- examples/sqlx-postgres/src/main.rs | 2 +- examples/sse/src/main.rs | 5 +++-- examples/static-file-server/src/main.rs | 5 +++-- examples/stream-to-file/src/main.rs | 2 +- examples/templates/src/main.rs | 2 +- examples/testing/src/main.rs | 5 +++-- examples/tls-graceful-shutdown/src/main.rs | 2 +- examples/tls-rustls/src/main.rs | 2 +- examples/todos/src/main.rs | 5 +++-- examples/tokio-postgres/src/main.rs | 2 +- examples/tokio-redis/src/main.rs | 2 +- examples/tracing-aka-logging/src/main.rs | 6 +++++- examples/validator/src/main.rs | 2 +- examples/versioning/src/main.rs | 2 +- examples/websockets/src/main.rs | 5 +++-- 38 files changed, 70 insertions(+), 50 deletions(-) diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 149ffe0d..77baada1 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -36,7 +36,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_chat=trace".into()), + .unwrap_or_else(|_| format!("{}=trace", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/compression/src/main.rs b/examples/compression/src/main.rs index 1fa1bb49..b487f34e 100644 --- a/examples/compression/src/main.rs +++ b/examples/compression/src/main.rs @@ -12,7 +12,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example-compression=trace".into()), + .unwrap_or_else(|_| format!("{}=trace", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/consume-body-in-extractor-or-middleware/src/main.rs b/examples/consume-body-in-extractor-or-middleware/src/main.rs index 95714f3a..473c34b9 100644 --- a/examples/consume-body-in-extractor-or-middleware/src/main.rs +++ b/examples/consume-body-in-extractor-or-middleware/src/main.rs @@ -22,7 +22,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_consume_body_in_extractor_or_middleware=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/customize-extractor-error/src/main.rs b/examples/customize-extractor-error/src/main.rs index e8820326..48188352 100644 --- a/examples/customize-extractor-error/src/main.rs +++ b/examples/customize-extractor-error/src/main.rs @@ -16,7 +16,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_customize_extractor_error=trace".into()), + .unwrap_or_else(|_| format!("{}=trace", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/customize-path-rejection/src/main.rs b/examples/customize-path-rejection/src/main.rs index 4231eabf..def83cc0 100644 --- a/examples/customize-path-rejection/src/main.rs +++ b/examples/customize-path-rejection/src/main.rs @@ -20,7 +20,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_customize_path_rejection=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/dependency-injection/src/main.rs b/examples/dependency-injection/src/main.rs index b8e1a451..0170966e 100644 --- a/examples/dependency-injection/src/main.rs +++ b/examples/dependency-injection/src/main.rs @@ -25,7 +25,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_dependency_injection=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/diesel-async-postgres/src/main.rs b/examples/diesel-async-postgres/src/main.rs index ee42ac10..8a97a9da 100644 --- a/examples/diesel-async-postgres/src/main.rs +++ b/examples/diesel-async-postgres/src/main.rs @@ -57,7 +57,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_diesel_async_postgres=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/diesel-postgres/src/main.rs b/examples/diesel-postgres/src/main.rs index 605660d0..0c5852d2 100644 --- a/examples/diesel-postgres/src/main.rs +++ b/examples/diesel-postgres/src/main.rs @@ -54,7 +54,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tokio_postgres=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/error-handling/src/main.rs b/examples/error-handling/src/main.rs index 6981f59e..0ad9f43c 100644 --- a/examples/error-handling/src/main.rs +++ b/examples/error-handling/src/main.rs @@ -45,8 +45,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_error_handling=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/form/src/main.rs b/examples/form/src/main.rs index 3f9ed095..02ea2352 100644 --- a/examples/form/src/main.rs +++ b/examples/form/src/main.rs @@ -13,7 +13,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_form=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/global-404-handler/src/main.rs b/examples/global-404-handler/src/main.rs index 38b02943..bf1d8a95 100644 --- a/examples/global-404-handler/src/main.rs +++ b/examples/global-404-handler/src/main.rs @@ -17,7 +17,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_global_404_handler=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/graceful-shutdown/src/main.rs b/examples/graceful-shutdown/src/main.rs index d3388c83..533cf8f1 100644 --- a/examples/graceful-shutdown/src/main.rs +++ b/examples/graceful-shutdown/src/main.rs @@ -21,7 +21,11 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { - "example_graceful_shutdown=debug,tower_http=debug,axum=trace".into() + format!( + "{}=debug,tower_http=debug,axum=trace", + env!("CARGO_CRATE_NAME") + ) + .into() }), ) .with(tracing_subscriber::fmt::layer().without_time()) diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index b60ed03d..90aa5aa8 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -36,8 +36,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_http_proxy=trace,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=trace,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/jwt/src/main.rs b/examples/jwt/src/main.rs index 85211851..8df845a4 100644 --- a/examples/jwt/src/main.rs +++ b/examples/jwt/src/main.rs @@ -61,7 +61,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_jwt=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/key-value-store/src/main.rs b/examples/key-value-store/src/main.rs index 1e2a5e74..571dbaf0 100644 --- a/examples/key-value-store/src/main.rs +++ b/examples/key-value-store/src/main.rs @@ -33,8 +33,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_key_value_store=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/low-level-openssl/src/main.rs b/examples/low-level-openssl/src/main.rs index f2839d61..7c483010 100644 --- a/examples/low-level-openssl/src/main.rs +++ b/examples/low-level-openssl/src/main.rs @@ -15,7 +15,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_low_level_openssl=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/low-level-rustls/src/main.rs b/examples/low-level-rustls/src/main.rs index 660225d7..7f5c994e 100644 --- a/examples/low-level-rustls/src/main.rs +++ b/examples/low-level-rustls/src/main.rs @@ -29,7 +29,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_low_level_rustls=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/multipart-form/src/main.rs b/examples/multipart-form/src/main.rs index ecf5191f..30fcfc70 100644 --- a/examples/multipart-form/src/main.rs +++ b/examples/multipart-form/src/main.rs @@ -17,8 +17,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_multipart_form=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/oauth/src/main.rs b/examples/oauth/src/main.rs index 659ce261..b35da7c6 100644 --- a/examples/oauth/src/main.rs +++ b/examples/oauth/src/main.rs @@ -35,7 +35,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_oauth=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/parse-body-based-on-content-type/src/main.rs b/examples/parse-body-based-on-content-type/src/main.rs index bae4ec1d..035b5707 100644 --- a/examples/parse-body-based-on-content-type/src/main.rs +++ b/examples/parse-body-based-on-content-type/src/main.rs @@ -22,7 +22,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { - "example_parse_body_based_on_content_type=debug,tower_http=debug".into() + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() }), ) .with(tracing_subscriber::fmt::layer()) diff --git a/examples/print-request-response/src/main.rs b/examples/print-request-response/src/main.rs index 5e0d4d1d..84f14f2d 100644 --- a/examples/print-request-response/src/main.rs +++ b/examples/print-request-response/src/main.rs @@ -20,8 +20,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_print_request_response=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/prometheus-metrics/src/main.rs b/examples/prometheus-metrics/src/main.rs index bb0e9c9c..fe76121c 100644 --- a/examples/prometheus-metrics/src/main.rs +++ b/examples/prometheus-metrics/src/main.rs @@ -63,8 +63,9 @@ async fn start_metrics_server() { async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_prometheus_metrics=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/reqwest-response/src/main.rs b/examples/reqwest-response/src/main.rs index 1b8a91d5..a1ba33cf 100644 --- a/examples/reqwest-response/src/main.rs +++ b/examples/reqwest-response/src/main.rs @@ -23,8 +23,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_reqwest_response=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/sqlx-postgres/src/main.rs b/examples/sqlx-postgres/src/main.rs index 46571115..fb8a855d 100644 --- a/examples/sqlx-postgres/src/main.rs +++ b/examples/sqlx-postgres/src/main.rs @@ -31,7 +31,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tokio_postgres=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/sse/src/main.rs b/examples/sse/src/main.rs index 73e7511e..4f616f6b 100644 --- a/examples/sse/src/main.rs +++ b/examples/sse/src/main.rs @@ -24,8 +24,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_sse=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/static-file-server/src/main.rs b/examples/static-file-server/src/main.rs index 707d2ee3..148af57c 100644 --- a/examples/static-file-server/src/main.rs +++ b/examples/static-file-server/src/main.rs @@ -19,8 +19,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_static_file_server=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/stream-to-file/src/main.rs b/examples/stream-to-file/src/main.rs index a595d0d8..73cb6364 100644 --- a/examples/stream-to-file/src/main.rs +++ b/examples/stream-to-file/src/main.rs @@ -25,7 +25,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_stream_to_file=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/templates/src/main.rs b/examples/templates/src/main.rs index 3a6c8231..6fdf4847 100644 --- a/examples/templates/src/main.rs +++ b/examples/templates/src/main.rs @@ -19,7 +19,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_templates=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index 9e33027e..c6dbcf5c 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -18,8 +18,9 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_testing=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/tls-graceful-shutdown/src/main.rs b/examples/tls-graceful-shutdown/src/main.rs index cc5b6ecb..f42ac435 100644 --- a/examples/tls-graceful-shutdown/src/main.rs +++ b/examples/tls-graceful-shutdown/src/main.rs @@ -28,7 +28,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tls_graceful_shutdown=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/tls-rustls/src/main.rs b/examples/tls-rustls/src/main.rs index 3649c75c..88da6e53 100644 --- a/examples/tls-rustls/src/main.rs +++ b/examples/tls-rustls/src/main.rs @@ -30,7 +30,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tls_rustls=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 2fdac41b..273f30e9 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -36,8 +36,9 @@ use uuid::Uuid; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_todos=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/tokio-postgres/src/main.rs b/examples/tokio-postgres/src/main.rs index effc0320..8980f621 100644 --- a/examples/tokio-postgres/src/main.rs +++ b/examples/tokio-postgres/src/main.rs @@ -21,7 +21,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tokio_postgres=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/tokio-redis/src/main.rs b/examples/tokio-redis/src/main.rs index f0109f21..b767a514 100644 --- a/examples/tokio-redis/src/main.rs +++ b/examples/tokio-redis/src/main.rs @@ -23,7 +23,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_tokio_redis=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/tracing-aka-logging/src/main.rs b/examples/tracing-aka-logging/src/main.rs index 74a2055a..30c16f19 100644 --- a/examples/tracing-aka-logging/src/main.rs +++ b/examples/tracing-aka-logging/src/main.rs @@ -25,7 +25,11 @@ async fn main() { tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { // axum logs rejections from built-in extractors with the `axum::rejection` // target, at `TRACE` level. `axum::rejection=trace` enables showing those events - "example_tracing_aka_logging=debug,tower_http=debug,axum::rejection=trace".into() + format!( + "{}=debug,tower_http=debug,axum::rejection=trace", + env!("CARGO_CRATE_NAME") + ) + .into() }), ) .with(tracing_subscriber::fmt::layer()) diff --git a/examples/validator/src/main.rs b/examples/validator/src/main.rs index 85c4ac18..5612333b 100644 --- a/examples/validator/src/main.rs +++ b/examples/validator/src/main.rs @@ -29,7 +29,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_validator=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/versioning/src/main.rs b/examples/versioning/src/main.rs index a1d96e83..4ada19b8 100644 --- a/examples/versioning/src/main.rs +++ b/examples/versioning/src/main.rs @@ -20,7 +20,7 @@ async fn main() { tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_versioning=debug".into()), + .unwrap_or_else(|_| format!("{}=debug", env!("CARGO_CRATE_NAME")).into()), ) .with(tracing_subscriber::fmt::layer()) .init(); diff --git a/examples/websockets/src/main.rs b/examples/websockets/src/main.rs index 9c3b9dbb..7b964404 100644 --- a/examples/websockets/src/main.rs +++ b/examples/websockets/src/main.rs @@ -45,8 +45,9 @@ use futures::{sink::SinkExt, stream::StreamExt}; async fn main() { tracing_subscriber::registry() .with( - tracing_subscriber::EnvFilter::try_from_default_env() - .unwrap_or_else(|_| "example_websockets=debug,tower_http=debug".into()), + tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { + format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME")).into() + }), ) .with(tracing_subscriber::fmt::layer()) .init();