feat: verbose flag (#541)

This commit is contained in:
Tomás
2022-12-20 14:41:04 -03:00
committed by GitHub
parent 7184e4df3f
commit 2dc5b80ef0
2 changed files with 33 additions and 5 deletions

View File

@ -11,8 +11,12 @@ use crate::{
/// main function that parses cli and runs command
pub async fn run() -> eyre::Result<()> {
let opt = Cli::parse();
reth_tracing::build_subscriber(if opt.silent { TracingMode::Silent } else { TracingMode::All })
.init();
reth_tracing::build_subscriber(if opt.silent {
TracingMode::Silent
} else {
TracingMode::from(opt.verbose)
})
.init();
match opt.command {
Commands::Node(command) => command.execute().await,

View File

@ -31,21 +31,45 @@ pub mod reth_tracing {
/// Tracing modes
pub enum TracingMode {
/// Enable all info traces.
/// Enable all traces.
All,
/// Disable tracing
/// Enable debug traces.
Debug,
/// Enable info traces.
Info,
/// Enable warn traces.
Warn,
/// Enable error traces.
Error,
/// Disable tracing.
Silent,
}
impl TracingMode {
fn into_env_filter(self) -> EnvFilter {
match self {
Self::All => EnvFilter::new("reth=info"),
Self::All => EnvFilter::new("reth=trace"),
Self::Debug => EnvFilter::new("reth=debug"),
Self::Info => EnvFilter::new("reth=info"),
Self::Warn => EnvFilter::new("reth=warn"),
Self::Error => EnvFilter::new("reth=error"),
Self::Silent => EnvFilter::new(""),
}
}
}
impl From<u8> for TracingMode {
fn from(value: u8) -> Self {
match value {
0 => Self::Error,
1 => Self::Warn,
2 => Self::Info,
3 => Self::Debug,
_ => Self::All,
}
}
}
/// Build subscriber
// TODO: JSON/systemd support
pub fn build_subscriber(mods: TracingMode) -> impl Subscriber {