From 0264e5c78e426317f2ca61301de7f50459db19c2 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 8 Jun 2023 16:44:04 +0100 Subject: [PATCH] feat: [#177] new config option for log level ```toml log_level = "info" ``` The level can be: - `off` - `error` - `warn` - `info` - `debug` - `trace` --- config-idx-back.local.toml | 2 ++ config.local.toml | 2 ++ src/app.rs | 4 +++- src/bootstrap/logging.rs | 6 ++---- src/config.rs | 3 +++ src/console/commands/import_tracker_statistics.rs | 4 +++- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config-idx-back.local.toml b/config-idx-back.local.toml index 5f93c0e6..9b6264f6 100644 --- a/config-idx-back.local.toml +++ b/config-idx-back.local.toml @@ -1,3 +1,5 @@ +log_level = "info" + [website] name = "Torrust" diff --git a/config.local.toml b/config.local.toml index 5a11fbea..3bb1093e 100644 --- a/config.local.toml +++ b/config.local.toml @@ -1,3 +1,5 @@ +log_level = "info" + [website] name = "Torrust" diff --git a/src/app.rs b/src/app.rs index a2bceb2f..872e3d9a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -30,7 +30,9 @@ pub struct Running { #[allow(clippy::too_many_lines)] pub async fn run(configuration: Configuration, api_implementation: &Implementation) -> Running { - logging::setup(); + let log_level = configuration.settings.read().await.log_level.clone(); + + logging::setup(&log_level); let configuration = Arc::new(configuration); diff --git a/src/bootstrap/logging.rs b/src/bootstrap/logging.rs index 303c5775..8546720f 100644 --- a/src/bootstrap/logging.rs +++ b/src/bootstrap/logging.rs @@ -13,10 +13,8 @@ use log::{info, LevelFilter}; static INIT: Once = Once::new(); -pub fn setup() { - // todo: load log level from configuration. - - let level = config_level_or_default(&None); +pub fn setup(log_level: &Option) { + let level = config_level_or_default(log_level); if level == log::LevelFilter::Off { return; diff --git a/src/config.rs b/src/config.rs index 8348edd3..0db50ea9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -257,6 +257,9 @@ impl Default for ImageCache { /// The whole configuration for the backend. #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct TorrustBackend { + /// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`, + /// `Debug` and `Trace`. Default is `Info`. + pub log_level: Option, /// The website customizable values. pub website: Website, /// The tracker configuration. diff --git a/src/console/commands/import_tracker_statistics.rs b/src/console/commands/import_tracker_statistics.rs index 2040ca95..579cca0c 100644 --- a/src/console/commands/import_tracker_statistics.rs +++ b/src/console/commands/import_tracker_statistics.rs @@ -85,7 +85,9 @@ pub async fn import() { let configuration = init_configuration().await; - logging::setup(); + let log_level = configuration.settings.read().await.log_level.clone(); + + logging::setup(&log_level); let cfg = Arc::new(configuration);