From 6608f73a2e635656e325a98cd8a52b1addafc4a9 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 25 Mar 2024 10:07:31 -0500 Subject: [PATCH] switch to tracing --- Cargo.lock | 1 + packages/cli/Cargo.toml | 1 + packages/cli/src/lib.rs | 3 --- packages/cli/src/logging.rs | 46 ------------------------------------- packages/cli/src/main.rs | 5 +--- 5 files changed, 3 insertions(+), 53 deletions(-) delete mode 100644 packages/cli/src/logging.rs diff --git a/Cargo.lock b/Cargo.lock index e32aa954c..f0cb05c71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2062,6 +2062,7 @@ dependencies = [ "toml_edit 0.21.1", "tower", "tower-http", + "tracing-subscriber", "walkdir", "wasm-bindgen-cli-support", "zip", diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml index e10d2c270..240e8ee0c 100644 --- a/packages/cli/Cargo.toml +++ b/packages/cli/Cargo.toml @@ -94,6 +94,7 @@ interprocess = { workspace = true } # interprocess-docfix = { version = "1.2.2" } ignore = "0.4.22" env_logger = "0.11.3" +tracing-subscriber = "0.3.18" [features] default = [] diff --git a/packages/cli/src/lib.rs b/packages/cli/src/lib.rs index 5c904d7ba..37d234aa8 100644 --- a/packages/cli/src/lib.rs +++ b/packages/cli/src/lib.rs @@ -15,8 +15,5 @@ pub use cli::*; pub mod error; pub use error::*; -pub mod logging; -pub use logging::*; - #[cfg(feature = "plugin")] pub mod plugin; diff --git a/packages/cli/src/logging.rs b/packages/cli/src/logging.rs deleted file mode 100644 index 0d902f86f..000000000 --- a/packages/cli/src/logging.rs +++ /dev/null @@ -1,46 +0,0 @@ -use fern::colors::{Color, ColoredLevelConfig}; - -pub fn set_up_logging() { - // configure colors for the whole line - let colors_line = ColoredLevelConfig::new() - .error(Color::Red) - .warn(Color::Yellow) - // we actually don't need to specify the color for debug and info, they are white by default - .info(Color::White) - .debug(Color::White) - // depending on the terminals color scheme, this is the same as the background color - .trace(Color::BrightBlack); - - // configure colors for the name of the level. - // since almost all of them are the same as the color for the whole line, we - // just clone `colors_line` and overwrite our changes - let colors_level = colors_line.info(Color::Green); - // here we set up our fern Dispatch - fern::Dispatch::new() - .format(move |out, message, record| { - out.finish(format_args!( - "{color_line}[{level}{color_line}] {message}\x1B[0m", - color_line = format_args!( - "\x1B[{}m", - colors_line.get_color(&record.level()).to_fg_str() - ), - level = colors_level.color(record.level()), - )); - }) - .level(match std::env::var("DIOXUS_LOG") { - Ok(level) => match level.to_lowercase().as_str() { - "error" => log::LevelFilter::Error, - "warn" => log::LevelFilter::Warn, - "info" => log::LevelFilter::Info, - "debug" => log::LevelFilter::Debug, - "trace" => log::LevelFilter::Trace, - _ => { - panic!("Invalid log level: {}", level) - } - }, - Err(_) => log::LevelFilter::Info, - }) - .chain(std::io::stdout()) - .apply() - .unwrap(); -} diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index 4943e6e3b..07b2609bf 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -11,10 +11,7 @@ use Commands::*; async fn main() -> anyhow::Result<()> { let args = Cli::parse(); - #[cfg(debug_assertions)] - env_logger::init(); - - // set_up_logging(); + tracing_subscriber::fmt::init(); match args.action { Translate(opts) => opts