Skip to content

Commit

Permalink
feat: [torrust#177] new config option for log level
Browse files Browse the repository at this point in the history
```toml
log_level = "info"
```

The level can be:

- `off`
- `error`
- `warn`
- `info`
- `debug`
- `trace`
  • Loading branch information
josecelano committed Jun 8, 2023
1 parent 937d4d9 commit 0264e5c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config-idx-back.local.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
log_level = "info"

[website]
name = "Torrust"

Expand Down
2 changes: 2 additions & 0 deletions config.local.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
log_level = "info"

[website]
name = "Torrust"

Expand Down
4 changes: 3 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions src/bootstrap/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
let level = config_level_or_default(log_level);

if level == log::LevelFilter::Off {
return;
Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// The website customizable values.
pub website: Website,
/// The tracker configuration.
Expand Down
4 changes: 3 additions & 1 deletion src/console/commands/import_tracker_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 0264e5c

Please sign in to comment.