Skip to content

Commit b12418a

Browse files
committed
Configurable log level
1 parent bd66bc9 commit b12418a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::Parser;
2+
use tracing::Level;
23

34
#[derive(Parser, Clone)]
45
#[command(version, about, long_about = None)]
@@ -43,6 +44,10 @@ pub struct Configuration {
4344
/// Use empty string to disable (not recommended).
4445
#[arg(short = 'a', long, env)]
4546
pub http_server_password: String,
47+
48+
/// Log level (trace, debug, info, warn, error)
49+
#[arg(short = 'e', long, env, default_value = "INFO")]
50+
pub log_level: Level,
4651
}
4752

4853
impl Configuration {

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use anyhow::{Context, Result};
1616
use config::Configuration;
1717
use std::sync::{Arc, Mutex};
1818
use tokio::sync::mpsc::channel;
19-
use tracing::{info, Level};
19+
use tracing::info;
2020

2121
#[tokio::main]
2222
async fn main() -> Result<()> {
@@ -27,14 +27,15 @@ async fn main() -> Result<()> {
2727
// Set up basic logging to stdout
2828
let subscriber = tracing_subscriber::fmt()
2929
.compact()
30-
.with_max_level(Level::INFO)
30+
.with_max_level(config.log_level)
3131
.with_target(false)
3232
.with_ansi(false)
3333
.finish();
3434
tracing::subscriber::set_global_default(subscriber)
3535
.expect("Failed to set up default tracing subscriber");
3636

3737
info!("DMARC Report Analyzer");
38+
info!("Log Level: {}", config.log_level);
3839

3940
// Prepare shared application state
4041
let state = Arc::new(Mutex::new(AppState::default()));

0 commit comments

Comments
 (0)