Skip to content

Commit

Permalink
Merge pull request #1388 from eclipse-zenoh/dev/logs
Browse files Browse the repository at this point in the history
Improve error handling and logs in examples
  • Loading branch information
Mallets authored Sep 10, 2024
2 parents 485194b + 45224eb commit e72e4d4
Show file tree
Hide file tree
Showing 62 changed files with 198 additions and 199 deletions.
2 changes: 1 addition & 1 deletion commons/zenoh-codec/tests/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ fn codec_shm_info() {
// Common
#[test]
fn codec_extension() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

macro_rules! run_extension_single {
($ext:ty, $buff:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_alloc_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use zenoh::{
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");
run().await.unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zenoh_ext::SubscriberForward;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, forward) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, selector, payload, target, timeout) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, timeout) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const N: usize = 10;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, selector, mut payload, target, timeout) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let config = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zenoh_examples::CommonArgs;

fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, warmup, size, n, express) = parse_args();
let session = zenoh::open(config).wait().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_ping_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use zenoh_examples::CommonArgs;

fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, warmup, size, n) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use zenoh_examples::CommonArgs;

fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, express) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, payload, attachment) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const N: usize = 10;
#[tokio::main]
async fn main() -> Result<(), ZError> {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, path, payload) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");
let (config, sm_size, size) = parse_args();

let z = zenoh::open(config).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use zenoh_examples::CommonArgs;

fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");
let args = Args::parse();

let mut prio = Priority::DEFAULT;
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, size, interval) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, payload) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_put_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, payload) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, payload, complete) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_queryable_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const N: usize = 10;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, payload, complete) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_scout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use zenoh::{config::WhatAmI, scout, Config};
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

println!("Scouting...");
let receiver = scout(WhatAmI::Peer | WhatAmI::Router, Config::default())
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, complete) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr, history) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs;
#[tokio::main]
async fn main() {
// Initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, key_expr) = parse_args();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Drop for Stats {

fn main() {
// initiate logging
zenoh::try_init_log_from_env();
zenoh::init_log_from_env_or("error");

let (config, m, n) = parse_args();

Expand Down
24 changes: 12 additions & 12 deletions io/zenoh-transport/tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async fn run(endpoints: &[EndPoint]) {
#[cfg(feature = "transport_tcp")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_tcp() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
format!("tcp/127.0.0.1:{}", 7000).parse().unwrap(),
Expand All @@ -113,7 +113,7 @@ async fn endpoint_tcp() {
#[cfg(feature = "transport_udp")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_udp() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
format!("udp/127.0.0.1:{}", 7010).parse().unwrap(),
Expand All @@ -126,7 +126,7 @@ async fn endpoint_udp() {
#[cfg(all(feature = "transport_unixsock-stream", target_family = "unix"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_unix() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Remove the files if they still exists
let f1 = "zenoh-test-unix-socket-0.sock";
let f2 = "zenoh-test-unix-socket-1.sock";
Expand All @@ -147,7 +147,7 @@ async fn endpoint_unix() {
#[cfg(feature = "transport_ws")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_ws() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
format!("ws/127.0.0.1:{}", 7020).parse().unwrap(),
Expand All @@ -160,7 +160,7 @@ async fn endpoint_ws() {
#[cfg(feature = "transport_unixpipe")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_unixpipe() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
"unixpipe/endpoint_unixpipe".parse().unwrap(),
Expand All @@ -174,7 +174,7 @@ async fn endpoint_unixpipe() {
#[cfg(all(feature = "transport_tcp", feature = "transport_udp"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_tcp_udp() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
format!("tcp/127.0.0.1:{}", 7030).parse().unwrap(),
Expand All @@ -193,7 +193,7 @@ async fn endpoint_tcp_udp() {
))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_tcp_udp_unix() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Remove the file if it still exists
let f1 = "zenoh-test-unix-socket-2.sock";
let _ = std::fs::remove_file(f1);
Expand All @@ -217,7 +217,7 @@ async fn endpoint_tcp_udp_unix() {
))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_tcp_unix() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Remove the file if it still exists
let f1 = "zenoh-test-unix-socket-3.sock";
let _ = std::fs::remove_file(f1);
Expand All @@ -239,7 +239,7 @@ async fn endpoint_tcp_unix() {
))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_udp_unix() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Remove the file if it still exists
let f1 = "zenoh-test-unix-socket-4.sock";
let _ = std::fs::remove_file(f1); // Define the locators
Expand All @@ -258,7 +258,7 @@ async fn endpoint_udp_unix() {
async fn endpoint_tls() {
use zenoh_link::tls::config::*;

zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// NOTE: this an auto-generated pair of certificate and key.
// The target domain is localhost, so it has no real
Expand Down Expand Up @@ -337,7 +337,7 @@ AXVFFIgCSluyrolaD6CWD9MqOex4YOfJR2bNxI7lFvuK4AwjyUJzT1U1HXib17mM
async fn endpoint_quic() {
use zenoh_link::quic::config::*;

zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// NOTE: this an auto-generated pair of certificate and key.
// The target domain is localhost, so it has no real
Expand Down Expand Up @@ -413,7 +413,7 @@ AXVFFIgCSluyrolaD6CWD9MqOex4YOfJR2bNxI7lFvuK4AwjyUJzT1U1HXib17mM
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn endpoint_vsock() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");
// Define the locators
let endpoints: Vec<EndPoint> = vec![
"vsock/-1:1234".parse().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/multicast_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod tests {
#[cfg(feature = "transport_udp")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn transport_multicast_compression_udp_only() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// Define the locator
let endpoints: Vec<EndPoint> = vec![
Expand Down
2 changes: 1 addition & 1 deletion io/zenoh-transport/tests/multicast_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ mod tests {
#[cfg(all(feature = "transport_compression", feature = "transport_udp"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn transport_multicast_udp_only() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// Define the locator
let endpoints: Vec<EndPoint> = vec![
Expand Down
6 changes: 3 additions & 3 deletions io/zenoh-transport/tests/transport_whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn run(endpoints: &[EndPoint]) {
#[cfg(feature = "transport_tcp")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn transport_whitelist_tcp() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// Define the locators
let endpoints: Vec<EndPoint> = vec![
Expand All @@ -133,7 +133,7 @@ async fn transport_whitelist_tcp() {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[ignore]
async fn transport_whitelist_unixpipe() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// Define the locators
let endpoints: Vec<EndPoint> = vec![
Expand All @@ -147,7 +147,7 @@ async fn transport_whitelist_unixpipe() {
#[cfg(all(feature = "transport_vsock", target_os = "linux"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn transport_whitelist_vsock() {
zenoh_util::try_init_log_from_env();
zenoh_util::init_log_from_env_or("error");

// Define the locators
let endpoints: Vec<EndPoint> = vec![
Expand Down
Loading

0 comments on commit e72e4d4

Please sign in to comment.