Skip to content

Commit

Permalink
feat: log final config after processing all config sources
Browse files Browse the repository at this point in the history
We print to logs the final configuration used to run the tracker (after Figment processes
all sources):

```output
Loading extra configuration from file: `storage/tracker/etc/tracker.toml` ...
2024-07-01T15:29:09.785334Z  INFO torrust_tracker::bootstrap::logging: Logging initialized
2024-07-01T15:29:09.785862Z  INFO torrust_tracker::bootstrap::app: Configuration:
 {
  "logging": {
    "log_level": "info"
  },
  "core": {
    "announce_policy": {
      "interval": 120,
      "interval_min": 120
    },
    "database": {
      "driver": "Sqlite3",
      "path": "./storage/tracker/lib/database/sqlite3.db"
    },
    "inactive_peer_cleanup_interval": 600,
    "listed": false,
    "net": {
      "external_ip": "0.0.0.0",
      "on_reverse_proxy": false
    },
    "private": true,
    "tracker_policy": {
      "max_peer_timeout": 900,
      "persistent_torrent_completed_stat": false,
      "remove_peerless_torrents": true
    },
    "tracker_usage_statistics": true
  },
  "udp_trackers": null,
  "http_trackers": null,
  "http_api": null,
  "health_check_api": {
    "bind_address": "127.0.0.1:1313"
  }
}
2024-07-01T15:29:09.785879Z  WARN torrust_tracker::app: No services enabled in configuration
2024-07-01T15:29:09.785920Z  INFO torrust_tracker::app: No UDP blocks in configuration
2024-07-01T15:29:09.785923Z  INFO torrust_tracker::app: No HTTP blocks in configuration
2024-07-01T15:29:09.785924Z  INFO torrust_tracker::app: No API block in configuration
2024-07-01T15:29:09.785941Z  INFO HEALTH CHECK API: Starting on: http://127.0.0.1:1313
2024-07-01T15:29:09.786035Z  INFO HEALTH CHECK API: Started on: http://127.0.0.1:1313
```
  • Loading branch information
josecelano committed Jul 1, 2024
1 parent ddfbde3 commit 397ef0f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ impl Info {
let env_var_config_toml_path = ENV_VAR_CONFIG_TOML_PATH.to_string();

let config_toml = if let Ok(config_toml) = env::var(env_var_config_toml) {
println!("Loading configuration from environment variable:\n {config_toml}");
println!("Loading extra configuration from environment variable:\n {config_toml}");

Check warning on line 114 in packages/configuration/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/lib.rs#L114

Added line #L114 was not covered by tests
Some(config_toml)
} else {
None
};

let config_toml_path = if let Ok(config_toml_path) = env::var(env_var_config_toml_path) {
println!("Loading configuration from file: `{config_toml_path}` ...");
println!("Loading extra configuration from file: `{config_toml_path}` ...");

Check warning on line 121 in packages/configuration/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/lib.rs#L121

Added line #L121 was not covered by tests
config_toml_path
} else {
println!("Loading configuration from default configuration file: `{default_config_toml_path}` ...");
println!("Loading extra configuration from default configuration file: `{default_config_toml_path}` ...");
default_config_toml_path
};

Expand Down
16 changes: 16 additions & 0 deletions packages/configuration/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,26 @@ impl Configuration {
}

/// Encodes the configuration to TOML.
///
/// # Panics
///
/// Will panic if it can't be converted to TOML.
#[must_use]
fn to_toml(&self) -> String {
// code-review: do we need to use Figment also to serialize into toml?
toml::to_string(self).expect("Could not encode TOML value")
}

/// Encodes the configuration to JSON.
///
/// # Panics
///
/// Will panic if it can't be converted to JSON.
#[must_use]
pub fn to_json(&self) -> String {

Check warning on line 365 in packages/configuration/src/v2/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/v2/mod.rs#L365

Added line #L365 was not covered by tests
// code-review: do we need to use Figment also to serialize into json?
serde_json::to_string_pretty(self).expect("Could not encode JSON value")
}

Check warning on line 368 in packages/configuration/src/v2/mod.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/v2/mod.rs#L367-L368

Added lines #L367 - L368 were not covered by tests
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::sync::Arc;

use torrust_tracker_clock::static_time;
use torrust_tracker_configuration::Configuration;
use tracing::info;

use super::config::initialize_configuration;
use crate::bootstrap;
Expand All @@ -26,8 +27,11 @@ use crate::shared::crypto::ephemeral_instance_keys;
#[must_use]
pub fn setup() -> (Configuration, Arc<Tracker>) {
let configuration = initialize_configuration();

let tracker = initialize_with_configuration(&configuration);

info!("Configuration:\n{}", configuration.to_json());

Check warning on line 33 in src/bootstrap/app.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/app.rs#L33

Added line #L33 was not covered by tests

(configuration, tracker)
}

Expand Down

0 comments on commit 397ef0f

Please sign in to comment.