Skip to content

Commit

Permalink
Replace simplelog with tracing_subscriber::fmt (rust-lang#525)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
NobodyXu committed Nov 10, 2022
1 parent e378be7 commit 3841762
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 58 deletions.
103 changes: 85 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions crates/bin/Cargo.toml
Expand Up @@ -29,11 +29,15 @@ dirs = "4.0.0"
log = "0.4.17"
miette = "5.4.1"
mimalloc = { version = "0.1.31", default-features = false, optional = true }
once_cell = "1.16.0"
semver = "1.0.14"
simplelog = "0.12.0"
tempfile = "3.3.0"
tokio = { version = "1.21.2", features = ["rt-multi-thread"], default-features = false }
tracing = { version = "0.1.37", features = ["log-always"], default-features = false }
tracing-core = "0.1.30"
tracing = { version = "0.1.37", default-features = false }
tracing-log = { version = "0.1.3", default-features = false }
tracing-appender = "0.2.2"
tracing-subscriber = { version = "0.3.16", features = ["fmt", "json"], default-features = false }

[build-dependencies]
embed-resource = "1.7.4"
Expand Down
4 changes: 4 additions & 0 deletions crates/bin/src/args.rs
Expand Up @@ -188,6 +188,10 @@ pub struct Args {
#[clap(help_heading = "Options", long, value_enum, value_name = "VERSION")]
pub min_tls_version: Option<TLSVersion>,

/// Print logs in json format to be parsable.
#[clap(help_heading = "Options", long)]
pub json_output: bool,

/// Print version information
#[clap(help_heading = "Meta", short = 'V')]
pub version: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/src/bin_util.rs
@@ -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;

Expand All @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/bin/src/lib.rs
Expand Up @@ -2,4 +2,5 @@ pub mod args;
pub mod bin_util;
pub mod entry;
pub mod install_path;
pub mod logging;
pub mod ui;

0 comments on commit 3841762

Please sign in to comment.