diff options
author | zjp <jiping_zhou@foxmail.com> | 2023-05-12 19:13:50 +0800 |
---|---|---|
committer | zjp <jiping_zhou@foxmail.com> | 2023-05-12 19:13:50 +0800 |
commit | 818d5cdc0e3de89a464107378649f92a0c215ed1 (patch) | |
tree | 2b10d18f2fa246e035d7c804b0c36bc31e30c4de | |
parent | d1699dfaf1eadcc4a650de979764a6815c1f44d2 (diff) |
rm env_logger; use tracing instead
-rw-r--r-- | Cargo.lock | 18 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/bin/main.rs | 17 | ||||
-rw-r--r-- | src/commands/core/mod.rs | 2 | ||||
-rw-r--r-- | src/commands/mod.rs | 2 | ||||
-rw-r--r-- | src/filesystem.rs | 2 |
6 files changed, 14 insertions, 29 deletions
@@ -261,16 +261,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] -name = "env_logger" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" -dependencies = [ - "humantime", - "log", -] - -[[package]] name = "errno" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -355,12 +345,6 @@ dependencies = [ ] [[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] name = "indexmap" version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -472,10 +456,8 @@ dependencies = [ "dns_common", "dns_common_derive", "edit", - "env_logger", "etcetera", "lazy_static", - "log", "regex", "remove_dir_all 0.8.2", "serde", @@ -36,8 +36,6 @@ serde_yaml = "0.9.21" dns_common_derive = { version = "0.2.1" } dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] } unicode-width = "0.1.10" -log = "0.4" -env_logger = { version = "0.10", default_features = false, features = ["humantime"] } [lib] name = "navi" diff --git a/src/bin/main.rs b/src/bin/main.rs index 48c2fa0..a9b90b0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,5 +1,6 @@ extern crate navi; +use dns_common::prelude::{debug, error, tracing, tracing_subscriber}; use thiserror::Error; #[derive(Error, Debug)] @@ -26,16 +27,20 @@ impl FileAnIssue { fn main() -> Result<(), anyhow::Error> { init_logger()?; navi::handle().map_err(|e| { - log::error!("{e:?}"); + error!("{e:?}"); FileAnIssue::new(e).into() }) } fn init_logger() -> anyhow::Result<()> { - let file = std::fs::File::create("navi.log")?; - env_logger::builder() - .target(env_logger::Target::Pipe(Box::new(file))) - .init(); - + tracing::subscriber::set_global_default( + tracing_subscriber::fmt() + .with_ansi(false) + // TODO: config_path/navi.log + .with_writer(std::fs::File::create("navi.log")?) + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .finish(), + )?; + debug!("tracing initialized"); Ok(()) } diff --git a/src/commands/core/mod.rs b/src/commands/core/mod.rs index 2a3d334..8055125 100644 --- a/src/commands/core/mod.rs +++ b/src/commands/core/mod.rs @@ -45,7 +45,7 @@ pub fn init(fetcher: Box<dyn Fetcher>) -> Result<()> { pub fn get_fetcher() -> Result<Box<dyn Fetcher>> { let source = CONFIG.source(); - log::debug!("{source:#?}"); + debug!("{source:#?}"); match source { Source::Cheats(query) => { let lines = cheatsh::call(&query)?; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 257df1c..4537177 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -12,7 +12,7 @@ use crate::prelude::*; pub fn handle() -> Result<()> { use crate::config::Command::*; - log::debug!("CONFIG = {:#?}", &*CONFIG); + debug!("CONFIG = {:#?}", &*CONFIG); match CONFIG.cmd() { None => commands::core::main(), diff --git a/src/filesystem.rs b/src/filesystem.rs index ed0f32e..fe4df97 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -181,7 +181,7 @@ impl fetcher::Fetcher for Fetcher { } } - log::debug!("filesystem::Fetcher = {self:#?}"); + debug!("filesystem::Fetcher = {self:#?}"); Ok(found_something) } |