mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-01 17:50:03 +00:00
Replace simplelog
with tracing_subscriber::fmt
(#525)
* Disable feat log-always of dep tracing * Add dep tracing-log 0.1.3 with no feat * Add new dep tracing-appender v0.2.2 * Add dep tracing-subscriber 0.3.16 with feat fmt and json * Fix `MainExit::report`: Do not use `log::{error, warn}` since `MainExit::report` might be called with no `log`ger, it can only use `println!` and `eprintln!`. * Use `tracing_subscriber::fmt` instead of `simple_log` * Rm unused dep simplelog from crates/bin * Fix `BinstallError::report`: Avoid `log::{warn, error}` since they might be called after `tracing_appender::WorkerGuard` is dropped. * Make tracing output more readable to end users * Add new dep tracing-core v0.1.30 * Add new dep once_cell v1.16.0 * Refactor: Extract new mod `logging` * Add new option `Args::json_output` * Fix `MainExit::report`: Ignore io error * Fix `BinstallError::report`: Ignore IO error Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
e378be73df
commit
3841762a5b
9 changed files with 290 additions and 59 deletions
|
@ -1,16 +1,10 @@
|
|||
use std::{
|
||||
cmp::min,
|
||||
io::{self, BufRead, Write},
|
||||
thread,
|
||||
};
|
||||
|
||||
use log::{LevelFilter, STATIC_MAX_LEVEL};
|
||||
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use binstalk::errors::BinstallError;
|
||||
|
||||
use crate::args::Args;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UIThreadInner {
|
||||
|
@ -102,24 +96,3 @@ impl UIThread {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn logging(args: &Args) {
|
||||
let log_level = min(args.log_level, STATIC_MAX_LEVEL);
|
||||
|
||||
// Setup logging
|
||||
let mut log_config = ConfigBuilder::new();
|
||||
|
||||
if log_level != LevelFilter::Trace {
|
||||
log_config.add_filter_allow_str("binstalk");
|
||||
log_config.add_filter_allow_str("cargo_binstall");
|
||||
}
|
||||
|
||||
log_config.set_location_level(LevelFilter::Off);
|
||||
TermLogger::init(
|
||||
log_level,
|
||||
log_config.build(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue