Skip to content

Commit

Permalink
chore(cli): make tokio console opt-in, cleanup default filters to hid…
Browse files Browse the repository at this point in the history
…e spammy trace logs
  • Loading branch information
ozwaldorf committed Oct 16, 2023
1 parent 5a19a97 commit 76ca832
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
12 changes: 8 additions & 4 deletions core/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ pub struct Args {
#[arg(short, long, global = true, default_value_t = String::from("~/.lightning/config.toml") )]
pub config: String,
/// Determines that we should be using the mock consensus backend.
#[arg(long, global = true)]
#[arg(long, global = true, default_value_t = false)]
pub with_mock_consensus: bool,
/// Enable the Tokio Console asynchronous debugger.
#[arg(long, global = true, default_value_t = false)]
pub with_console: bool,
/// Enable code locations when printing logs.
#[arg(long, global = true, default_value_t = true)]
pub with_log_locations: bool,
/// Increases the level of verbosity (the max level is -vvv).
#[arg(short, global = true, action = ArgAction::Count)]
pub verbose: u8,
/// Print code location on console logs
#[arg(long, global = true)]
pub log_location: bool,

#[command(subcommand)]
pub cmd: Command,
}
Expand Down
38 changes: 23 additions & 15 deletions core/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ impl Cli {
}

fn setup(&self) {
// Spawn tokio_console server
let console_layer = console_subscriber::Builder::default()
.with_default_env()
.server_addr(([0, 0, 0, 0], 9001))
.spawn();

// Build the filter from cli args, or environment variable
// Build the filter from cli args, or override if environment variable is set.
let env_filter = EnvFilter::builder()
.with_default_directive(
match self.args.verbose {
Expand All @@ -85,15 +79,29 @@ impl Cli {
.into(),
)
.from_env_lossy()
.add_directive("quinn=off".parse().unwrap())
.add_directive("anemo=off".parse().unwrap());
.add_directive("quinn=warn".parse().unwrap())
.add_directive("anemo=warn".parse().unwrap())
.add_directive("rustls=warn".parse().unwrap())
.add_directive("tokio=warn".parse().unwrap())
.add_directive("runtime=warn".parse().unwrap());

// Initialize the base logging registry
let registry = tracing_subscriber::registry().with(
tracing_subscriber::fmt::layer()
.with_file(self.args.with_log_locations)
.with_filter(env_filter),
);

// Initialize the registry for logging events
tracing_subscriber::registry()
.with(console_layer)
.with(tracing_subscriber::fmt::layer().with_file(true))
.with(env_filter)
.init();
if self.args.with_console {
// Spawn tokio_console server
let console_layer = console_subscriber::Builder::default()
.with_default_env()
.server_addr(([0, 0, 0, 0], 9001))
.spawn();
registry.with(console_layer).init();
} else {
registry.init();
}
}

fn resolve_config_path(&self) -> Result<ResolvedPathBuf> {
Expand Down

0 comments on commit 76ca832

Please sign in to comment.