diff --git a/Cargo.lock b/Cargo.lock index aff6c4950a..a38a41f589 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5229,10 +5229,10 @@ dependencies = [ "rustc_version 0.4.0", "tokio", "tracing", + "tracing-subscriber", "zenoh", "zenoh-collections", "zenoh-ext", - "zenoh-util", ] [[package]] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 90281ae558..5d48f3fbe8 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -34,13 +34,13 @@ transport_unixpipe = ["zenoh/transport_unixpipe"] [dependencies] tokio = { workspace = true, features = ["rt-multi-thread", "time", "io-std"] } clap = { workspace = true, features = ["derive"] } -zenoh-util = { workspace = true } flume = { workspace = true } futures = { workspace = true } git-version = { workspace = true } json5 = { workspace = true } zenoh-collections = { workspace = true } tracing = { workspace = true } +tracing-subscriber = { workspace = true } zenoh = { workspace = true, default-features = true } zenoh-ext = { workspace = true } diff --git a/examples/examples/z_alloc_shm.rs b/examples/examples/z_alloc_shm.rs index abdbb2e443..009734b0ec 100644 --- a/examples/examples/z_alloc_shm.rs +++ b/examples/examples/z_alloc_shm.rs @@ -22,8 +22,8 @@ use zenoh::{ #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); + run().await.unwrap() } @@ -144,3 +144,9 @@ async fn run() -> ZResult<()> { // Publish SHM buffer publisher.put(sbuf).await } + +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} diff --git a/examples/examples/z_delete.rs b/examples/examples/z_delete.rs index 294d1b850a..d3c364e794 100644 --- a/examples/examples/z_delete.rs +++ b/examples/examples/z_delete.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr) = parse_args(); @@ -31,6 +30,12 @@ async fn main() { session.close().await.unwrap(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] diff --git a/examples/examples/z_forward.rs b/examples/examples/z_forward.rs index deb82a2a7f..7680202216 100644 --- a/examples/examples/z_forward.rs +++ b/examples/examples/z_forward.rs @@ -18,8 +18,7 @@ use zenoh_ext::SubscriberForward; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, forward) = parse_args(); @@ -34,6 +33,12 @@ async fn main() { subscriber.forward(publisher).await.unwrap(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/**")] diff --git a/examples/examples/z_get.rs b/examples/examples/z_get.rs index e04fc8bcf6..7b2e301420 100644 --- a/examples/examples/z_get.rs +++ b/examples/examples/z_get.rs @@ -19,8 +19,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, selector, value, target, timeout) = parse_args(); @@ -63,6 +62,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::ValueEnum, Clone, Copy, Debug)] #[value(rename_all = "SCREAMING_SNAKE_CASE")] enum Qt { diff --git a/examples/examples/z_get_liveliness.rs b/examples/examples/z_get_liveliness.rs index 150308aea4..1dc7e42b32 100644 --- a/examples/examples/z_get_liveliness.rs +++ b/examples/examples/z_get_liveliness.rs @@ -19,8 +19,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, timeout) = parse_args(); @@ -48,6 +47,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(Parser, Clone, Debug)] struct Args { #[arg(short, long, default_value = "group1/**")] diff --git a/examples/examples/z_get_shm.rs b/examples/examples/z_get_shm.rs index bfb9213ab5..cf58adacc3 100644 --- a/examples/examples/z_get_shm.rs +++ b/examples/examples/z_get_shm.rs @@ -30,8 +30,7 @@ const N: usize = 10; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, selector, mut value, target, timeout) = parse_args(); @@ -101,6 +100,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::ValueEnum, Clone, Copy, Debug)] #[value(rename_all = "SCREAMING_SNAKE_CASE")] enum Qt { diff --git a/examples/examples/z_info.rs b/examples/examples/z_info.rs index 281532e236..57d75f3776 100644 --- a/examples/examples/z_info.rs +++ b/examples/examples/z_info.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let config = parse_args(); @@ -37,6 +36,12 @@ async fn main() { ); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[command(flatten)] diff --git a/examples/examples/z_liveliness.rs b/examples/examples/z_liveliness.rs index 71b1fe4e4e..e8bfd50caa 100644 --- a/examples/examples/z_liveliness.rs +++ b/examples/examples/z_liveliness.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr) = parse_args(); @@ -38,6 +37,12 @@ async fn main() { }; } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "group1/zenoh-rs")] diff --git a/examples/examples/z_ping.rs b/examples/examples/z_ping.rs index 56ba47b7f5..8aff7936ea 100644 --- a/examples/examples/z_ping.rs +++ b/examples/examples/z_ping.rs @@ -18,8 +18,7 @@ use zenoh::{bytes::ZBytes, key_expr::keyexpr, prelude::*, publisher::CongestionC use zenoh_examples::CommonArgs; fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, warmup, size, n, express) = parse_args(); let session = zenoh::open(config).wait().unwrap(); @@ -76,6 +75,12 @@ fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(Parser)] struct Args { /// express for sending data diff --git a/examples/examples/z_ping_shm.rs b/examples/examples/z_ping_shm.rs index a88a9f59a6..48c6dd0682 100644 --- a/examples/examples/z_ping_shm.rs +++ b/examples/examples/z_ping_shm.rs @@ -25,8 +25,7 @@ use zenoh::{ use zenoh_examples::CommonArgs; fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, warmup, size, n) = parse_args(); @@ -102,6 +101,12 @@ fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(Parser)] struct Args { #[arg(short, long, default_value = "1")] diff --git a/examples/examples/z_pong.rs b/examples/examples/z_pong.rs index ecf2aa1643..3c5416cf93 100644 --- a/examples/examples/z_pong.rs +++ b/examples/examples/z_pong.rs @@ -16,8 +16,7 @@ use zenoh::{key_expr::keyexpr, prelude::*, publisher::CongestionControl, Config} use zenoh_examples::CommonArgs; fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, express) = parse_args(); @@ -49,6 +48,12 @@ fn main() { std::thread::park(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { /// express for sending data diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index 6812246cfa..178cf4a0cc 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -19,8 +19,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, value, attachment) = parse_args(); @@ -39,6 +38,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-pub")] diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index 93ce1df553..0974fae720 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -27,8 +27,7 @@ const N: usize = 10; #[tokio::main] async fn main() -> Result<(), ZError> { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, path, value) = parse_args(); @@ -92,6 +91,12 @@ async fn main() -> Result<(), ZError> { Ok(()) } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-pub")] diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index 2d52668ac9..b7f6c3fd41 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -23,8 +23,8 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); + let (mut config, sm_size, size) = parse_args(); // A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` to operate @@ -71,6 +71,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "32")] diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index 8ea7226c8a..71cfb4e0cb 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -23,8 +23,8 @@ use zenoh::{ use zenoh_examples::CommonArgs; fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); + let args = Args::parse(); let mut prio = Priority::DEFAULT; @@ -68,6 +68,12 @@ fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { /// express for sending data diff --git a/examples/examples/z_pull.rs b/examples/examples/z_pull.rs index 3127e76c14..d99db0aae2 100644 --- a/examples/examples/z_pull.rs +++ b/examples/examples/z_pull.rs @@ -19,8 +19,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, size, interval) = parse_args(); @@ -91,6 +90,12 @@ async fn main() { // } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Debug)] struct SubArgs { #[arg(short, long, default_value = "demo/example/**")] diff --git a/examples/examples/z_put.rs b/examples/examples/z_put.rs index f56fbf2c8c..4b538f94fe 100644 --- a/examples/examples/z_put.rs +++ b/examples/examples/z_put.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, value) = parse_args(); @@ -29,6 +28,12 @@ async fn main() { session.put(&key_expr, value).await.unwrap(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] diff --git a/examples/examples/z_put_float.rs b/examples/examples/z_put_float.rs index 234579b8d5..cd1d78a3f9 100644 --- a/examples/examples/z_put_float.rs +++ b/examples/examples/z_put_float.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, value) = parse_args(); @@ -31,6 +30,12 @@ async fn main() { session.close().await.unwrap(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-put")] diff --git a/examples/examples/z_queryable.rs b/examples/examples/z_queryable.rs index eb950766ab..f910decbe2 100644 --- a/examples/examples/z_queryable.rs +++ b/examples/examples/z_queryable.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, key_expr, value, complete) = parse_args(); @@ -69,6 +68,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-queryable")] diff --git a/examples/examples/z_queryable_shm.rs b/examples/examples/z_queryable_shm.rs index 5cc8e301d3..64b9c3063d 100644 --- a/examples/examples/z_queryable_shm.rs +++ b/examples/examples/z_queryable_shm.rs @@ -27,8 +27,7 @@ const N: usize = 10; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, key_expr, value, complete) = parse_args(); @@ -100,6 +99,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/zenoh-rs-queryable")] diff --git a/examples/examples/z_scout.rs b/examples/examples/z_scout.rs index f099beae46..dcefc4ef4b 100644 --- a/examples/examples/z_scout.rs +++ b/examples/examples/z_scout.rs @@ -15,8 +15,7 @@ use zenoh::{config::WhatAmI, scout, Config}; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); println!("Scouting..."); let receiver = scout(WhatAmI::Peer | WhatAmI::Router, Config::default()) @@ -33,3 +32,9 @@ async fn main() { // stop scouting receiver.stop(); } + +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} diff --git a/examples/examples/z_storage.rs b/examples/examples/z_storage.rs index 86d73da2bb..bd3e192189 100644 --- a/examples/examples/z_storage.rs +++ b/examples/examples/z_storage.rs @@ -27,8 +27,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr, complete) = parse_args(); @@ -73,6 +72,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "demo/example/**")] diff --git a/examples/examples/z_sub.rs b/examples/examples/z_sub.rs index 95cd5f8988..e4908f2579 100644 --- a/examples/examples/z_sub.rs +++ b/examples/examples/z_sub.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, key_expr) = parse_args(); @@ -55,6 +54,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct SubArgs { #[arg(short, long, default_value = "demo/example/**")] diff --git a/examples/examples/z_sub_liveliness.rs b/examples/examples/z_sub_liveliness.rs index 86420381e1..082292fa80 100644 --- a/examples/examples/z_sub_liveliness.rs +++ b/examples/examples/z_sub_liveliness.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (config, key_expr) = parse_args(); @@ -48,6 +47,12 @@ async fn main() { } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "group1/**")] diff --git a/examples/examples/z_sub_shm.rs b/examples/examples/z_sub_shm.rs index 04ba8e9753..48f9fa7ac9 100644 --- a/examples/examples/z_sub_shm.rs +++ b/examples/examples/z_sub_shm.rs @@ -17,8 +17,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { - // Initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, key_expr) = parse_args(); @@ -68,6 +67,12 @@ async fn main() { // } } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct SubArgs { #[arg(short, long, default_value = "demo/example/**")] diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index bee15ada2b..98118945a7 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -68,8 +68,7 @@ impl Drop for Stats { } fn main() { - // initiate logging - zenoh_util::try_init_log_from_env(); + initialize_logging(); let (mut config, m, n) = parse_args(); @@ -98,6 +97,12 @@ fn main() { std::thread::park(); } +fn initialize_logging() { + tracing_subscriber::fmt() + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .init() +} + #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] struct Args { #[arg(short, long, default_value = "10")]