Skip to content

Commit 0264e5c

Browse files
committed
feat: [#177] new config option for log level
```toml log_level = "info" ``` The level can be: - `off` - `error` - `warn` - `info` - `debug` - `trace`
1 parent 937d4d9 commit 0264e5c

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

config-idx-back.local.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
log_level = "info"
2+
13
[website]
24
name = "Torrust"
35

config.local.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
log_level = "info"
2+
13
[website]
24
name = "Torrust"
35

src/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ pub struct Running {
3030

3131
#[allow(clippy::too_many_lines)]
3232
pub async fn run(configuration: Configuration, api_implementation: &Implementation) -> Running {
33-
logging::setup();
33+
let log_level = configuration.settings.read().await.log_level.clone();
34+
35+
logging::setup(&log_level);
3436

3537
let configuration = Arc::new(configuration);
3638

src/bootstrap/logging.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ use log::{info, LevelFilter};
1313

1414
static INIT: Once = Once::new();
1515

16-
pub fn setup() {
17-
// todo: load log level from configuration.
18-
19-
let level = config_level_or_default(&None);
16+
pub fn setup(log_level: &Option<String>) {
17+
let level = config_level_or_default(log_level);
2018

2119
if level == log::LevelFilter::Off {
2220
return;

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ impl Default for ImageCache {
257257
/// The whole configuration for the backend.
258258
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
259259
pub struct TorrustBackend {
260+
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
261+
/// `Debug` and `Trace`. Default is `Info`.
262+
pub log_level: Option<String>,
260263
/// The website customizable values.
261264
pub website: Website,
262265
/// The tracker configuration.

src/console/commands/import_tracker_statistics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ pub async fn import() {
8585

8686
let configuration = init_configuration().await;
8787

88-
logging::setup();
88+
let log_level = configuration.settings.read().await.log_level.clone();
89+
90+
logging::setup(&log_level);
8991

9092
let cfg = Arc::new(configuration);
9193

0 commit comments

Comments
 (0)