From c4b15872deab7c42a90dccf9a73ff4ce5ed72544 Mon Sep 17 00:00:00 2001 From: Gabriele Baldoni Date: Thu, 18 Apr 2024 08:01:22 +0000 Subject: [PATCH] feat(tracing): use tracing and zenoh-util log (#70) * feat(tracing): use tracing and zenoh-util log Signed-off-by: gabrik * feat(tracing): using zenoh main branch Signed-off-by: gabrik * fix: calling right function from module Signed-off-by: gabrik * chore: using new try_init_log_from_env Signed-off-by: gabrik --------- Signed-off-by: gabrik --- Cargo.lock | 70 ++++-------------------------------------------------- Cargo.toml | 3 +-- src/lib.rs | 6 ++--- 3 files changed, 7 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3f943a..66e456c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,7 +123,7 @@ dependencies = [ "log", "parking", "polling", - "rustix 0.37.25", + "rustix", "slab", "socket2 0.4.9", "waker-fn", @@ -151,7 +151,7 @@ dependencies = [ "cfg-if", "event-listener 2.5.3", "futures-lite", - "rustix 0.37.25", + "rustix", "signal-hook", "windows-sys 0.48.0", ] @@ -530,19 +530,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -921,17 +908,6 @@ dependencies = [ "serde", ] -[[package]] -name = "is-terminal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix 0.38.32", - "windows-sys 0.48.0", -] - [[package]] name = "itoa" version = "1.0.9" @@ -1064,12 +1040,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - [[package]] name = "lock_api" version = "0.4.10" @@ -1744,23 +1714,10 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys 0.3.8", + "linux-raw-sys", "windows-sys 0.48.0", ] -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.4.2", - "errno", - "libc", - "linux-raw-sys 0.4.13", - "windows-sys 0.52.0", -] - [[package]] name = "rustls" version = "0.21.7" @@ -2198,15 +2155,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.48" @@ -2732,15 +2680,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2935,13 +2874,12 @@ version = "0.11.0-dev" dependencies = [ "async-std", "async-trait", - "env_logger", "git-version", "lazy_static", - "log", "rocksdb", "rustc_version", "serde_json", + "tracing", "uhlc 0.5.2", "zenoh", "zenoh-codec", diff --git a/Cargo.toml b/Cargo.toml index bb7a75a..7ee0604 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,12 +38,11 @@ stats = ["zenoh/stats"] [dependencies] async-std = "=1.12.0" async-trait = "0.1.66" -env_logger = "0.10.0" git-version = "0.3.5" lazy_static = "1.4.0" -log = "0.4.17" rocksdb = "0.20.1" serde_json = "1.0.94" +tracing = "0.1" uhlc = "0.5.2" zenoh = { git = "https://github.com/eclipse-zenoh/zenoh", branch = "main", features = [ "unstable", diff --git a/src/lib.rs b/src/lib.rs index b8ffcd5..3679bbd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,11 +14,11 @@ use async_std::sync::{Arc, Mutex}; use async_trait::async_trait; -use log::{debug, error, trace, warn}; use rocksdb::{ColumnFamilyDescriptor, Options, WriteBatch, DB}; use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration; +use tracing::{debug, error, trace, warn}; use uhlc::NTP64; use zenoh::buffers::{reader::HasReader, writer::HasWriter}; use zenoh::prelude::*; @@ -76,9 +76,7 @@ impl Plugin for RocksDbBackend { const PLUGIN_LONG_VERSION: &'static str = plugin_long_version!(); fn start(_name: &str, _config: &Self::StartArgs) -> ZResult { - // For some reasons env_logger is sometime not active in a loaded library. - // Try to activate it here, ignoring failures. - let _ = env_logger::try_init(); + zenoh_util::try_init_log_from_env(); debug!("RocksDB backend {}", Self::PLUGIN_LONG_VERSION); let root = if let Some(dir) = std::env::var_os(SCOPE_ENV_VAR) {