Skip to content

Commit

Permalink
feat!: [#878] make log_level config value mandatory
Browse files Browse the repository at this point in the history
Althought, it has a default value `info` so you can omit it in the TOML
config file.
  • Loading branch information
josecelano committed Jun 17, 2024
1 parent ef9461a commit 77dd938
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
7 changes: 3 additions & 4 deletions packages/configuration/src/v1/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Logging {
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
/// `Debug` and `Trace`. Default is `Info`.
#[serde(default = "Logging::default_log_level")]
pub log_level: Option<LogLevel>,
pub log_level: LogLevel,
}

impl Default for Logging {
Expand All @@ -20,8 +20,7 @@ impl Default for Logging {
}

impl Logging {
#[allow(clippy::unnecessary_wraps)]
fn default_log_level() -> Option<LogLevel> {
Some(LogLevel::Info)
fn default_log_level() -> LogLevel {
LogLevel::Info
}
}
2 changes: 1 addition & 1 deletion packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn ephemeral() -> Configuration {

let mut config = Configuration::default();

config.logging.log_level = Some(LogLevel::Off); // Change to `debug` for tests debugging
config.logging.log_level = LogLevel::Off; // Change to `debug` for tests debugging

// Ephemeral socket address for API
let api_port = 0u16;
Expand Down
19 changes: 8 additions & 11 deletions src/bootstrap/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static INIT: Once = Once::new();

/// It redirects the log info to the standard output with the log level defined in the configuration
pub fn setup(cfg: &Configuration) {
let tracing_level = config_level_or_default(&cfg.logging.log_level);
let tracing_level = map_to_tracing_level_filter(&cfg.logging.log_level);

if tracing_level == LevelFilter::OFF {
return;
Expand All @@ -31,17 +31,14 @@ pub fn setup(cfg: &Configuration) {
});
}

fn config_level_or_default(log_level: &Option<LogLevel>) -> LevelFilter {
fn map_to_tracing_level_filter(log_level: &LogLevel) -> LevelFilter {
match log_level {
None => LevelFilter::INFO,
Some(level) => match level {
LogLevel::Off => LevelFilter::OFF,
LogLevel::Error => LevelFilter::ERROR,
LogLevel::Warn => LevelFilter::WARN,
LogLevel::Info => LevelFilter::INFO,
LogLevel::Debug => LevelFilter::DEBUG,
LogLevel::Trace => LevelFilter::TRACE,
},
LogLevel::Off => LevelFilter::OFF,
LogLevel::Error => LevelFilter::ERROR,
LogLevel::Warn => LevelFilter::WARN,
LogLevel::Info => LevelFilter::INFO,
LogLevel::Debug => LevelFilter::DEBUG,
LogLevel::Trace => LevelFilter::TRACE,
}
}

Expand Down

0 comments on commit 77dd938

Please sign in to comment.