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:
Jiahao XU 2022-11-11 10:05:09 +11:00 committed by GitHub
parent e378be73df
commit 3841762a5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 290 additions and 59 deletions

View file

@ -1,12 +1,12 @@
use std::{
future::Future,
io::{self, Write},
process::{ExitCode, Termination},
time::Duration,
};
use binstalk::errors::BinstallError;
use binstalk::helpers::{signal::cancel_on_user_sig_term, tasks::AutoAbortJoinHandle};
use log::{error, info};
use miette::Result;
use tokio::runtime::Runtime;
@ -21,13 +21,13 @@ impl Termination for MainExit {
match self {
Self::Success(spent) => {
if let Some(spent) = spent {
info!("Done in {spent:?}");
writeln!(io::stdout(), "Done in {spent:?}").ok();
}
ExitCode::SUCCESS
}
Self::Error(err) => err.report(),
Self::Report(err) => {
error!("Fatal error:\n{err:?}");
writeln!(io::stderr(), "Fatal error:\n{err:?}").ok();
ExitCode::from(16)
}
}