fixup log level handling
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -28,12 +28,29 @@ enum Level {
|
|||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Level> for tracing::Level {
|
||||||
|
fn from(level: Level) -> Self {
|
||||||
|
match level {
|
||||||
|
Level::Debug => tracing::Level::DEBUG,
|
||||||
|
Level::Info => tracing::Level::INFO,
|
||||||
|
Level::Warn => tracing::Level::WARN,
|
||||||
|
Level::Error => tracing::Level::ERROR,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Level {
|
||||||
|
fn level(self) -> tracing::Level {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// TOML configuration to load
|
/// TOML configuration to load
|
||||||
#[arg(short, long, default_value_t = String::from("config.toml"))]
|
#[arg(short, long, default_value_t = String::from("config.toml"))]
|
||||||
config_file: String,
|
config_file: String,
|
||||||
#[arg(value_enum, default_value_t = Level::Warn)]
|
#[arg(value_enum, default_value_t = Level::Info)]
|
||||||
log_level: Level,
|
log_level: Level,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +119,16 @@ async fn dummy_consumer(mut chan: ChimemonTargetChannel, cancel: CancellationTok
|
|||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let args = Args::parse();
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or(EnvFilter::default()))
|
.with_env_filter(
|
||||||
|
EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or(EnvFilter::default().add_directive(args.log_level.level().into())),
|
||||||
|
)
|
||||||
// .event_format(format::Format::default().pretty())
|
// .event_format(format::Format::default().pretty())
|
||||||
.with_span_events(FmtSpan::CLOSE)
|
.with_span_events(FmtSpan::CLOSE)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let args = Args::parse();
|
|
||||||
|
|
||||||
info!("{PROGRAM_NAME} v{VERSION} starting...");
|
info!("{PROGRAM_NAME} v{VERSION} starting...");
|
||||||
let fig = Figment::new()
|
let fig = Figment::new()
|
||||||
.merge(Config::default())
|
.merge(Config::default())
|
||||||
|
|||||||
Reference in New Issue
Block a user