From 79b94b9bd651402d12624ec6de6c31fa0ceccf96 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 6 Mar 2022 12:37:00 +0100 Subject: [PATCH] Replace set_var usage in examples (#829) * examples: Fix inconsistent toml formatting * examples: Replace set_var usage --- examples/chat/Cargo.toml | 2 +- examples/chat/src/main.rs | 12 +++++++----- examples/customize-extractor-error/Cargo.toml | 2 +- examples/customize-extractor-error/src/main.rs | 13 ++++++++----- examples/customize-path-rejection/Cargo.toml | 2 +- examples/customize-path-rejection/src/main.rs | 13 ++++++++----- .../Cargo.toml | 2 +- .../src/main.rs | 16 ++++++++-------- examples/form/Cargo.toml | 2 +- examples/form/src/main.rs | 12 +++++++----- examples/global-404-handler/Cargo.toml | 2 +- examples/global-404-handler/src/main.rs | 12 +++++++----- examples/http-proxy/Cargo.toml | 2 +- examples/http-proxy/src/main.rs | 13 ++++++++----- examples/jwt/Cargo.toml | 2 +- examples/jwt/src/main.rs | 12 +++++++----- examples/key-value-store/Cargo.toml | 2 +- examples/key-value-store/src/main.rs | 13 ++++++++----- examples/low-level-rustls/Cargo.toml | 2 +- examples/low-level-rustls/src/main.rs | 12 +++++++----- examples/multipart-form/Cargo.toml | 2 +- examples/multipart-form/src/main.rs | 13 ++++++++----- examples/oauth/Cargo.toml | 2 +- examples/oauth/src/main.rs | 12 +++++++----- examples/print-request-response/Cargo.toml | 2 +- examples/print-request-response/src/main.rs | 16 ++++++++-------- examples/prometheus-metrics/src/main.rs | 13 ++++++++----- examples/readme/Cargo.toml | 2 +- examples/sessions/Cargo.toml | 2 +- examples/sessions/src/main.rs | 12 +++++++----- examples/sqlx-postgres/Cargo.toml | 2 +- examples/sqlx-postgres/src/main.rs | 12 +++++++----- examples/sse/Cargo.toml | 2 +- examples/sse/src/main.rs | 13 ++++++++----- examples/static-file-server/Cargo.toml | 2 +- examples/static-file-server/src/main.rs | 16 ++++++++-------- examples/templates/Cargo.toml | 2 +- examples/templates/src/main.rs | 12 +++++++----- examples/testing/src/main.rs | 13 ++++++++----- examples/tls-rustls/Cargo.toml | 2 +- examples/tls-rustls/src/main.rs | 12 +++++++----- examples/todos/Cargo.toml | 2 +- examples/todos/src/main.rs | 13 ++++++++----- examples/tokio-postgres/Cargo.toml | 2 +- examples/tokio-postgres/src/main.rs | 12 +++++++----- examples/tracing-aka-logging/Cargo.toml | 2 +- examples/tracing-aka-logging/src/main.rs | 16 ++++++++-------- examples/unix-domain-socket/Cargo.toml | 2 +- examples/unix-domain-socket/src/main.rs | 12 +++++++----- examples/validator/Cargo.toml | 2 +- examples/validator/src/main.rs | 11 +++++++---- examples/versioning/Cargo.toml | 2 +- examples/versioning/src/main.rs | 12 +++++++----- examples/websockets/Cargo.toml | 2 +- examples/websockets/src/main.rs | 13 ++++++++----- 55 files changed, 237 insertions(+), 178 deletions(-) diff --git a/examples/chat/Cargo.toml b/examples/chat/Cargo.toml index a777d539..d5139c73 100644 --- a/examples/chat/Cargo.toml +++ b/examples/chat/Cargo.toml @@ -10,4 +10,4 @@ futures = "0.3" tokio = { version = "1", features = ["full"] } tower = { version = "0.4", features = ["util"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/chat/src/main.rs b/examples/chat/src/main.rs index 52c02a90..6ad18669 100644 --- a/examples/chat/src/main.rs +++ b/examples/chat/src/main.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Mutex}, }; use tokio::sync::broadcast; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; // Our shared state struct AppState { @@ -31,11 +32,12 @@ struct AppState { #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_chat=trace") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_chat=trace".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let user_set = Mutex::new(HashSet::new()); let (tx, _rx) = broadcast::channel(100); diff --git a/examples/customize-extractor-error/Cargo.toml b/examples/customize-extractor-error/Cargo.toml index 02db1f88..897a797e 100644 --- a/examples/customize-extractor-error/Cargo.toml +++ b/examples/customize-extractor-error/Cargo.toml @@ -10,4 +10,4 @@ tokio = { version = "1.0", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/customize-extractor-error/src/main.rs b/examples/customize-extractor-error/src/main.rs index 2afba46f..119c4c08 100644 --- a/examples/customize-extractor-error/src/main.rs +++ b/examples/customize-extractor-error/src/main.rs @@ -14,14 +14,17 @@ use axum::{ use serde::{de::DeserializeOwned, Deserialize}; use serde_json::{json, Value}; use std::{borrow::Cow, net::SocketAddr}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_customize_extractor_error=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_customize_extractor_error=trace".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with a route let app = Router::new().route("/users", post(handler)); diff --git a/examples/customize-path-rejection/Cargo.toml b/examples/customize-path-rejection/Cargo.toml index d553c668..12539bf8 100644 --- a/examples/customize-path-rejection/Cargo.toml +++ b/examples/customize-path-rejection/Cargo.toml @@ -10,4 +10,4 @@ tokio = { version = "1.0", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/customize-path-rejection/src/main.rs b/examples/customize-path-rejection/src/main.rs index 2f2b856b..f78101f0 100644 --- a/examples/customize-path-rejection/src/main.rs +++ b/examples/customize-path-rejection/src/main.rs @@ -14,14 +14,17 @@ use axum::{ }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_customize_path_rejection=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_customize_path_rejection=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with a route let app = Router::new().route("/users/:user_id/teams/:team_id", get(handler)); diff --git a/examples/error-handling-and-dependency-injection/Cargo.toml b/examples/error-handling-and-dependency-injection/Cargo.toml index 6a99efc1..0ad43b8a 100644 --- a/examples/error-handling-and-dependency-injection/Cargo.toml +++ b/examples/error-handling-and-dependency-injection/Cargo.toml @@ -9,7 +9,7 @@ axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" uuid = { version = "0.8", features = ["v4", "serde"] } diff --git a/examples/error-handling-and-dependency-injection/src/main.rs b/examples/error-handling-and-dependency-injection/src/main.rs index 208bb103..b58c6432 100644 --- a/examples/error-handling-and-dependency-injection/src/main.rs +++ b/examples/error-handling-and-dependency-injection/src/main.rs @@ -18,18 +18,18 @@ use axum::{ use serde::{Deserialize, Serialize}; use serde_json::json; use std::{net::SocketAddr, sync::Arc}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use uuid::Uuid; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var( - "RUST_LOG", - "example_error_handling_and_dependency_injection=debug", - ) - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_error_handling_and_dependency_injection=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // Inject a `UserRepo` into our handlers via a trait object. This could be // the live implementation or just a mock for testing. diff --git a/examples/form/Cargo.toml b/examples/form/Cargo.toml index adef28f9..12b25c12 100644 --- a/examples/form/Cargo.toml +++ b/examples/form/Cargo.toml @@ -8,5 +8,5 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde = { version = "1.0", features = ["derive"] } diff --git a/examples/form/src/main.rs b/examples/form/src/main.rs index 4061e52c..6b11d0e6 100644 --- a/examples/form/src/main.rs +++ b/examples/form/src/main.rs @@ -7,14 +7,16 @@ use axum::{extract::Form, response::Html, routing::get, Router}; use serde::Deserialize; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_form=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_form=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with some routes let app = Router::new().route("/", get(show_form).post(accept_form)); diff --git a/examples/global-404-handler/Cargo.toml b/examples/global-404-handler/Cargo.toml index bbf9f5b7..95a3003c 100644 --- a/examples/global-404-handler/Cargo.toml +++ b/examples/global-404-handler/Cargo.toml @@ -9,4 +9,4 @@ axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tower = { version = "0.4", features = ["util"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/global-404-handler/src/main.rs b/examples/global-404-handler/src/main.rs index b51a5162..896f743f 100644 --- a/examples/global-404-handler/src/main.rs +++ b/examples/global-404-handler/src/main.rs @@ -12,14 +12,16 @@ use axum::{ Router, }; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_global_404_handler=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_global_404_handler=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with a route let app = Router::new().route("/", get(handler)); diff --git a/examples/http-proxy/Cargo.toml b/examples/http-proxy/Cargo.toml index 8978c6cb..9cd73466 100644 --- a/examples/http-proxy/Cargo.toml +++ b/examples/http-proxy/Cargo.toml @@ -10,4 +10,4 @@ tokio = { version = "1.0", features = ["full"] } hyper = { version = "0.14", features = ["full"] } tower = { version = "0.4", features = ["make"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index 88c2f1b9..a4b412bb 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -23,14 +23,17 @@ use hyper::upgrade::Upgraded; use std::net::SocketAddr; use tokio::net::TcpStream; use tower::{make::Shared, ServiceExt}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_http_proxy=trace,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_http_proxy=trace,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let router = Router::new().route("/", get(|| async { "Hello, World!" })); diff --git a/examples/jwt/Cargo.toml b/examples/jwt/Cargo.toml index b3ca07c5..2cc783ef 100644 --- a/examples/jwt/Cargo.toml +++ b/examples/jwt/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum", features = ["headers"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" headers = "0.3" diff --git a/examples/jwt/src/main.rs b/examples/jwt/src/main.rs index 5cae685b..0ac4053e 100644 --- a/examples/jwt/src/main.rs +++ b/examples/jwt/src/main.rs @@ -20,6 +20,7 @@ use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use serde_json::json; use std::{fmt::Display, net::SocketAddr}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; // Quick instructions // @@ -54,11 +55,12 @@ static KEYS: Lazy = Lazy::new(|| { #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_jwt=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_jwt=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let app = Router::new() .route("/protected", get(protected)) diff --git a/examples/key-value-store/Cargo.toml b/examples/key-value-store/Cargo.toml index 20c92ab2..e18a6489 100644 --- a/examples/key-value-store/Cargo.toml +++ b/examples/key-value-store/Cargo.toml @@ -8,6 +8,6 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] } tower-http = { version = "0.2.0", features = ["add-extension", "auth", "compression-full", "trace"] } diff --git a/examples/key-value-store/src/main.rs b/examples/key-value-store/src/main.rs index 62fc7477..649e25c2 100644 --- a/examples/key-value-store/src/main.rs +++ b/examples/key-value-store/src/main.rs @@ -27,14 +27,17 @@ use tower::{BoxError, ServiceBuilder}; use tower_http::{ auth::RequireAuthorizationLayer, compression::CompressionLayer, trace::TraceLayer, }; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_key_value_store=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_key_value_store=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // Build our application by composing routes let app = Router::new() diff --git a/examples/low-level-rustls/Cargo.toml b/examples/low-level-rustls/Cargo.toml index 4aa82359..ab753c71 100644 --- a/examples/low-level-rustls/Cargo.toml +++ b/examples/low-level-rustls/Cargo.toml @@ -13,4 +13,4 @@ tokio = { version = "1", features = ["full"] } tokio-rustls = "0.23" tower = { version = "0.4", features = ["make"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/low-level-rustls/src/main.rs b/examples/low-level-rustls/src/main.rs index 611949f0..31215899 100644 --- a/examples/low-level-rustls/src/main.rs +++ b/examples/low-level-rustls/src/main.rs @@ -18,14 +18,16 @@ use tokio_rustls::{ TlsAcceptor, }; use tower::MakeService; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_tls_rustls=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_tls_rustls=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let rustls_config = rustls_server_config( "examples/tls-rustls/self_signed_certs/key.pem", diff --git a/examples/multipart-form/Cargo.toml b/examples/multipart-form/Cargo.toml index 79e5f235..c270f7ec 100644 --- a/examples/multipart-form/Cargo.toml +++ b/examples/multipart-form/Cargo.toml @@ -8,5 +8,5 @@ publish = false axum = { path = "../../axum", features = ["multipart"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower-http = { version = "0.2.0", features = ["trace"] } diff --git a/examples/multipart-form/src/main.rs b/examples/multipart-form/src/main.rs index 6d1edf1e..87e70cc1 100644 --- a/examples/multipart-form/src/main.rs +++ b/examples/multipart-form/src/main.rs @@ -11,14 +11,17 @@ use axum::{ Router, }; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_multipart_form=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_multipart_form=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with some routes let app = Router::new() diff --git a/examples/oauth/Cargo.toml b/examples/oauth/Cargo.toml index a9926f51..edcb87b0 100644 --- a/examples/oauth/Cargo.toml +++ b/examples/oauth/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum", features = ["headers"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } oauth2 = "4.1" async-session = "3.0.0" serde = { version = "1.0", features = ["derive"] } diff --git a/examples/oauth/src/main.rs b/examples/oauth/src/main.rs index 6532f8be..d4dfaf35 100644 --- a/examples/oauth/src/main.rs +++ b/examples/oauth/src/main.rs @@ -27,16 +27,18 @@ use oauth2::{ }; use serde::{Deserialize, Serialize}; use std::{env, net::SocketAddr}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; static COOKIE_NAME: &str = "SESSION"; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_oauth=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_oauth=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // `MemoryStore` is just used as an example. Don't use this in production. let store = MemoryStore::new(); diff --git a/examples/print-request-response/Cargo.toml b/examples/print-request-response/Cargo.toml index 69781c11..3458ba3a 100644 --- a/examples/print-request-response/Cargo.toml +++ b/examples/print-request-response/Cargo.toml @@ -8,6 +8,6 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower = { version = "0.4", features = ["util", "filter"] } hyper = { version = "0.14", features = ["full"] } diff --git a/examples/print-request-response/src/main.rs b/examples/print-request-response/src/main.rs index 75109fb3..3357579f 100644 --- a/examples/print-request-response/src/main.rs +++ b/examples/print-request-response/src/main.rs @@ -13,17 +13,17 @@ use axum::{ Router, }; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var( - "RUST_LOG", - "example_print_request_response=debug,tower_http=debug", - ) - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_print_request_response=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let app = Router::new() .route("/", post(|| async move { "Hello from `POST /`" })) diff --git a/examples/prometheus-metrics/src/main.rs b/examples/prometheus-metrics/src/main.rs index f4e3944d..fc58882f 100644 --- a/examples/prometheus-metrics/src/main.rs +++ b/examples/prometheus-metrics/src/main.rs @@ -21,14 +21,17 @@ use std::{ net::SocketAddr, time::{Duration, Instant}, }; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_todos=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_todos=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let recorder_handle = setup_metrics_recorder(); diff --git a/examples/readme/Cargo.toml b/examples/readme/Cargo.toml index ed3d178c..c898d7cc 100644 --- a/examples/readme/Cargo.toml +++ b/examples/readme/Cargo.toml @@ -10,4 +10,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/sessions/Cargo.toml b/examples/sessions/Cargo.toml index fa65fcdb..caef8e11 100644 --- a/examples/sessions/Cargo.toml +++ b/examples/sessions/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum", features = ["headers"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } serde = { version = "1.0", features = ["derive"] } uuid = { version = "0.8", features = ["v4", "serde"] } async-session = "3.0.0" diff --git a/examples/sessions/src/main.rs b/examples/sessions/src/main.rs index 92876278..079c0dc2 100644 --- a/examples/sessions/src/main.rs +++ b/examples/sessions/src/main.rs @@ -21,17 +21,19 @@ use axum::{ use serde::{Deserialize, Serialize}; use std::fmt::Debug; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use uuid::Uuid; const AXUM_SESSION_COOKIE_NAME: &str = "axum_session"; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_sessions=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_sessions=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // `MemoryStore` just used as an example. Don't use this in production. let store = MemoryStore::new(); diff --git a/examples/sqlx-postgres/Cargo.toml b/examples/sqlx-postgres/Cargo.toml index 32bfb916..13b7ee43 100644 --- a/examples/sqlx-postgres/Cargo.toml +++ b/examples/sqlx-postgres/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } sqlx = { version = "0.5.10", features = ["runtime-tokio-rustls", "any", "postgres"] } diff --git a/examples/sqlx-postgres/src/main.rs b/examples/sqlx-postgres/src/main.rs index 9386b984..3e8f0525 100644 --- a/examples/sqlx-postgres/src/main.rs +++ b/examples/sqlx-postgres/src/main.rs @@ -21,16 +21,18 @@ use axum::{ Router, }; use sqlx::postgres::{PgPool, PgPoolOptions}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use std::{net::SocketAddr, time::Duration}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_tokio_postgres=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_tokio_postgres=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let db_connection_str = std::env::var("DATABASE_URL") .unwrap_or_else(|_| "postgres://postgres:password@localhost".to_string()); diff --git a/examples/sse/Cargo.toml b/examples/sse/Cargo.toml index c8c6b91f..e9df22a5 100644 --- a/examples/sse/Cargo.toml +++ b/examples/sse/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum", features = ["headers"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower-http = { version = "0.2.0", features = ["fs", "trace"] } futures = "0.3" tokio-stream = "0.1" diff --git a/examples/sse/src/main.rs b/examples/sse/src/main.rs index 772e9d01..2bcab4c5 100644 --- a/examples/sse/src/main.rs +++ b/examples/sse/src/main.rs @@ -15,14 +15,17 @@ use futures::stream::{self, Stream}; use std::{convert::Infallible, net::SocketAddr, time::Duration}; use tokio_stream::StreamExt as _; use tower_http::{services::ServeDir, trace::TraceLayer}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_sse=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_sse=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let static_files_service = get_service(ServeDir::new("examples/sse/assets").append_index_html_on_directories(true)) diff --git a/examples/static-file-server/Cargo.toml b/examples/static-file-server/Cargo.toml index 85e688e7..af39d550 100644 --- a/examples/static-file-server/Cargo.toml +++ b/examples/static-file-server/Cargo.toml @@ -8,5 +8,5 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower-http = { version = "0.2.0", features = ["fs", "trace"] } diff --git a/examples/static-file-server/src/main.rs b/examples/static-file-server/src/main.rs index 822377b1..7e1034ba 100644 --- a/examples/static-file-server/src/main.rs +++ b/examples/static-file-server/src/main.rs @@ -7,17 +7,17 @@ use axum::{http::StatusCode, routing::get_service, Router}; use std::net::SocketAddr; use tower_http::{services::ServeDir, trace::TraceLayer}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var( - "RUST_LOG", - "example_static_file_server=debug,tower_http=debug", - ) - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_static_file_server=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let app = Router::new() .nest( diff --git a/examples/templates/Cargo.toml b/examples/templates/Cargo.toml index ee27bd38..2a38fcec 100644 --- a/examples/templates/Cargo.toml +++ b/examples/templates/Cargo.toml @@ -8,5 +8,5 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } askama = "0.11" diff --git a/examples/templates/src/main.rs b/examples/templates/src/main.rs index 505e660b..ec47a083 100644 --- a/examples/templates/src/main.rs +++ b/examples/templates/src/main.rs @@ -13,14 +13,16 @@ use axum::{ Router, }; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_templates=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_templates=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with some routes let app = Router::new().route("/greet/:name", get(greet)); diff --git a/examples/testing/src/main.rs b/examples/testing/src/main.rs index b6677f68..2893188b 100644 --- a/examples/testing/src/main.rs +++ b/examples/testing/src/main.rs @@ -9,14 +9,17 @@ use axum::{ Json, Router, }; use tower_http::trace::TraceLayer; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_testing=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_testing=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000)); diff --git a/examples/tls-rustls/Cargo.toml b/examples/tls-rustls/Cargo.toml index 428d41f2..0521f0a1 100644 --- a/examples/tls-rustls/Cargo.toml +++ b/examples/tls-rustls/Cargo.toml @@ -9,4 +9,4 @@ axum = { path = "../../axum" } axum-server = { version = "0.3", features = ["tls-rustls"] } tokio = { version = "1", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/tls-rustls/src/main.rs b/examples/tls-rustls/src/main.rs index 666982b3..862fca22 100644 --- a/examples/tls-rustls/src/main.rs +++ b/examples/tls-rustls/src/main.rs @@ -7,14 +7,16 @@ use axum::{routing::get, Router}; use axum_server::tls_rustls::RustlsConfig; use std::net::SocketAddr; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_tls_rustls=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_tls_rustls=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let config = RustlsConfig::from_pem_file( "examples/tls-rustls/self_signed_certs/cert.pem", diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index ceb71751..896d2f7a 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower = { version = "0.4", features = ["util", "timeout"] } tower-http = { version = "0.2.0", features = ["add-extension", "trace"] } uuid = { version = "0.8", features = ["serde", "v4"] } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 85f5a86c..c4fd3ddd 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -30,15 +30,18 @@ use std::{ }; use tower::{BoxError, ServiceBuilder}; use tower_http::trace::TraceLayer; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use uuid::Uuid; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_todos=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_todos=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let db = Db::default(); diff --git a/examples/tokio-postgres/Cargo.toml b/examples/tokio-postgres/Cargo.toml index 32dcf145..79378437 100644 --- a/examples/tokio-postgres/Cargo.toml +++ b/examples/tokio-postgres/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } bb8 = "0.7.1" bb8-postgres = "0.7.0" tokio-postgres = "0.7.2" diff --git a/examples/tokio-postgres/src/main.rs b/examples/tokio-postgres/src/main.rs index 257f9280..2abac5ba 100644 --- a/examples/tokio-postgres/src/main.rs +++ b/examples/tokio-postgres/src/main.rs @@ -15,14 +15,16 @@ use bb8::{Pool, PooledConnection}; use bb8_postgres::PostgresConnectionManager; use std::net::SocketAddr; use tokio_postgres::NoTls; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_tokio_postgres=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_tokio_postgres=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // setup connection pool let manager = diff --git a/examples/tracing-aka-logging/Cargo.toml b/examples/tracing-aka-logging/Cargo.toml index d4470b03..4def1c16 100644 --- a/examples/tracing-aka-logging/Cargo.toml +++ b/examples/tracing-aka-logging/Cargo.toml @@ -8,5 +8,5 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower-http = { version = "0.2.0", features = ["trace"] } diff --git a/examples/tracing-aka-logging/src/main.rs b/examples/tracing-aka-logging/src/main.rs index da21a2f3..edce1635 100644 --- a/examples/tracing-aka-logging/src/main.rs +++ b/examples/tracing-aka-logging/src/main.rs @@ -14,17 +14,17 @@ use axum::{ use std::{net::SocketAddr, time::Duration}; use tower_http::{classify::ServerErrorsFailureClass, trace::TraceLayer}; use tracing::Span; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var( - "RUST_LOG", - "example_tracing_aka_logging=debug,tower_http=debug", - ) - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_tracing_aka_logging=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with a route let app = Router::new() diff --git a/examples/unix-domain-socket/Cargo.toml b/examples/unix-domain-socket/Cargo.toml index 2d10ed3c..c01d0fbe 100644 --- a/examples/unix-domain-socket/Cargo.toml +++ b/examples/unix-domain-socket/Cargo.toml @@ -8,7 +8,7 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } hyper = { version = "0.14", features = ["full"] } tower = { version = "0.4", features = ["util"] } futures = "0.3" diff --git a/examples/unix-domain-socket/src/main.rs b/examples/unix-domain-socket/src/main.rs index d5c1c3c2..6dbcec33 100644 --- a/examples/unix-domain-socket/src/main.rs +++ b/examples/unix-domain-socket/src/main.rs @@ -28,6 +28,7 @@ use tokio::{ net::{unix::UCred, UnixListener, UnixStream}, }; use tower::BoxError; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[cfg(not(unix))] fn main() { @@ -37,11 +38,12 @@ fn main() { #[cfg(unix)] #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); let path = PathBuf::from("/tmp/axum/helloworld"); diff --git a/examples/validator/Cargo.toml b/examples/validator/Cargo.toml index b3acb983..e4d148cc 100644 --- a/examples/validator/Cargo.toml +++ b/examples/validator/Cargo.toml @@ -12,5 +12,5 @@ serde = { version = "1.0", features = ["derive"] } thiserror = "1.0.29" tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } validator = { version = "0.14.0", features = ["derive"] } diff --git a/examples/validator/src/main.rs b/examples/validator/src/main.rs index 2d9e65d2..ed0d3463 100644 --- a/examples/validator/src/main.rs +++ b/examples/validator/src/main.rs @@ -21,14 +21,17 @@ use axum::{ use serde::{de::DeserializeOwned, Deserialize}; use std::net::SocketAddr; use thiserror::Error; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use validator::Validate; #[tokio::main] async fn main() { - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_validator=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_validator=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with a route let app = Router::new().route("/", get(handler)); diff --git a/examples/versioning/Cargo.toml b/examples/versioning/Cargo.toml index fac3a770..5a645237 100644 --- a/examples/versioning/Cargo.toml +++ b/examples/versioning/Cargo.toml @@ -8,4 +8,4 @@ publish = false axum = { path = "../../axum" } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/examples/versioning/src/main.rs b/examples/versioning/src/main.rs index 2266b9cc..2cde3edb 100644 --- a/examples/versioning/src/main.rs +++ b/examples/versioning/src/main.rs @@ -13,14 +13,16 @@ use axum::{ Router, }; use std::{collections::HashMap, net::SocketAddr}; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_versioning=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG").unwrap_or_else(|_| "example_versioning=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with some routes let app = Router::new().route("/:version/foo", get(handler)); diff --git a/examples/websockets/Cargo.toml b/examples/websockets/Cargo.toml index 91246da8..7d2ae9fe 100644 --- a/examples/websockets/Cargo.toml +++ b/examples/websockets/Cargo.toml @@ -8,6 +8,6 @@ publish = false axum = { path = "../../axum", features = ["ws", "headers"] } tokio = { version = "1.0", features = ["full"] } tracing = "0.1" -tracing-subscriber = { version="0.3", features = ["env-filter"] } +tracing-subscriber = { version = "0.3", features = ["env-filter"] } tower-http = { version = "0.2.0", features = ["fs", "trace"] } headers = "0.3" diff --git a/examples/websockets/src/main.rs b/examples/websockets/src/main.rs index 24ac232e..5657a53a 100644 --- a/examples/websockets/src/main.rs +++ b/examples/websockets/src/main.rs @@ -21,14 +21,17 @@ use tower_http::{ services::ServeDir, trace::{DefaultMakeSpan, TraceLayer}, }; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() { - // Set the RUST_LOG, if it hasn't been explicitly defined - if std::env::var_os("RUST_LOG").is_none() { - std::env::set_var("RUST_LOG", "example_websockets=debug,tower_http=debug") - } - tracing_subscriber::fmt::init(); + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + std::env::var("RUST_LOG") + .unwrap_or_else(|_| "example_websockets=debug,tower_http=debug".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); // build our application with some routes let app = Router::new()