rm env_logger; use tracing instead

This commit is contained in:
zjp 2023-05-12 19:13:50 +08:00 committed by Denis Isidoro
parent 196872b109
commit e2c4b2b67e
6 changed files with 14 additions and 29 deletions

18
Cargo.lock generated
View file

@ -260,16 +260,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" 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]] [[package]]
name = "errno" name = "errno"
version = "0.3.0" version = "0.3.0"
@ -354,12 +344,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "1.9.3"
@ -472,10 +456,8 @@ dependencies = [
"dns_common", "dns_common",
"dns_common_derive", "dns_common_derive",
"edit", "edit",
"env_logger",
"etcetera", "etcetera",
"lazy_static", "lazy_static",
"log",
"regex", "regex",
"remove_dir_all 0.8.2", "remove_dir_all 0.8.2",
"serde", "serde",

View file

@ -36,8 +36,6 @@ serde_yaml = "0.9.21"
dns_common_derive = { version = "0.2.1" } dns_common_derive = { version = "0.2.1" }
dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] } dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] }
unicode-width = "0.1.10" unicode-width = "0.1.10"
log = "0.4"
env_logger = { version = "0.10", default_features = false, features = ["humantime"] }
[lib] [lib]
name = "navi" name = "navi"

View file

@ -1,5 +1,6 @@
extern crate navi; extern crate navi;
use dns_common::prelude::{debug, error, tracing, tracing_subscriber};
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
@ -26,16 +27,20 @@ impl FileAnIssue {
fn main() -> Result<(), anyhow::Error> { fn main() -> Result<(), anyhow::Error> {
init_logger()?; init_logger()?;
navi::handle().map_err(|e| { navi::handle().map_err(|e| {
log::error!("{e:?}"); error!("{e:?}");
FileAnIssue::new(e).into() FileAnIssue::new(e).into()
}) })
} }
fn init_logger() -> anyhow::Result<()> { fn init_logger() -> anyhow::Result<()> {
let file = std::fs::File::create("navi.log")?; tracing::subscriber::set_global_default(
env_logger::builder() tracing_subscriber::fmt()
.target(env_logger::Target::Pipe(Box::new(file))) .with_ansi(false)
.init(); // 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(()) Ok(())
} }

View file

@ -45,7 +45,7 @@ pub fn init(fetcher: Box<dyn Fetcher>) -> Result<()> {
pub fn get_fetcher() -> Result<Box<dyn Fetcher>> { pub fn get_fetcher() -> Result<Box<dyn Fetcher>> {
let source = CONFIG.source(); let source = CONFIG.source();
log::debug!("{source:#?}"); debug!("{source:#?}");
match source { match source {
Source::Cheats(query) => { Source::Cheats(query) => {
let lines = cheatsh::call(&query)?; let lines = cheatsh::call(&query)?;

View file

@ -12,7 +12,7 @@ use crate::prelude::*;
pub fn handle() -> Result<()> { pub fn handle() -> Result<()> {
use crate::config::Command::*; use crate::config::Command::*;
log::debug!("CONFIG = {:#?}", &*CONFIG); debug!("CONFIG = {:#?}", &*CONFIG);
match CONFIG.cmd() { match CONFIG.cmd() {
None => commands::core::main(), None => commands::core::main(),

View file

@ -181,7 +181,7 @@ impl fetcher::Fetcher for Fetcher {
} }
} }
log::debug!("filesystem::Fetcher = {self:#?}"); debug!("filesystem::Fetcher = {self:#?}");
Ok(found_something) Ok(found_something)
} }