make tokio console optional and make it actually work

This commit is contained in:
cy 2025-04-26 15:37:54 -04:00
parent 5a3e6089b4
commit d524222a86
Signed by: cy
SSH key fingerprint: SHA256:o/geVWV4om1QhUSkKvDQeW/eAihwnjyXkqMwrVdbuts
3 changed files with 83 additions and 3 deletions

View file

@ -1,11 +1,11 @@
#![feature(let_chains)]
#![feature(extend_one)]
#![feature(exit_status_error)]
use std::path::PathBuf;
use anyhow::{Context, Result};
use clap::{Args, Parser, Subcommand};
use tracing_subscriber::{EnvFilter, prelude::*};
use push::Push;
use store::Store;
@ -26,6 +26,10 @@ mod uploader;
struct Cli {
#[command(subcommand)]
command: Commands,
/// Whether to enable tokio-console
#[arg(long)]
tokio_console: bool,
}
#[derive(Debug, Subcommand)]
@ -70,9 +74,8 @@ pub struct PushArgs {
#[tokio::main]
async fn main() -> Result<()> {
console_subscriber::init();
let cli = Cli::parse();
init_logging(cli.tokio_console);
match &cli.command {
Commands::Push(cli) => {
@ -87,3 +90,23 @@ async fn main() -> Result<()> {
Ok(())
}
fn init_logging(tokio_console: bool) {
let env_filter = EnvFilter::from_default_env();
let fmt_layer = tracing_subscriber::fmt::layer().with_filter(env_filter);
let console_layer = if tokio_console {
Some(console_subscriber::spawn())
} else {
None
};
tracing_subscriber::registry()
.with(fmt_layer)
.with(console_layer)
.init();
if tokio_console {
println!("tokio-console is enabled");
}
}