Skip to content

Commit

Permalink
feat!: [torrust#878] extract logging and core section in toml config …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
josecelano committed Jun 17, 2024
1 parent a6054f1 commit 60369da
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cargo build --release -p aquatic_udp_load_test
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.

```toml
[logging]
log_level = "error"

[[udp_trackers]]
Expand Down Expand Up @@ -163,6 +164,7 @@ Announce responses per info hash:
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.

```toml
[logging]
log_level = "error"

[[udp_trackers]]
Expand Down
27 changes: 27 additions & 0 deletions packages/configuration/src/v1/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use serde::{Deserialize, Serialize};

use crate::LogLevel;

#[allow(clippy::struct_excessive_bools)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
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>,
}

impl Default for Logging {
fn default() -> Self {
Self {
log_level: Self::default_log_level(),
}
}
}

impl Logging {
#[allow(clippy::unnecessary_wraps)]
fn default_log_level() -> Option<LogLevel> {
Some(LogLevel::Info)
}
}
14 changes: 12 additions & 2 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@
//! The default configuration is:
//!
//! ```toml
//! [logging]
//! log_level = "info"
//!
//! [core]
//! mode = "public"
//! db_driver = "Sqlite3"
//! db_path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down Expand Up @@ -233,6 +236,7 @@
pub mod core;
pub mod health_check_api;
pub mod http_tracker;
pub mod logging;
pub mod tracker_api;
pub mod udp_tracker;

Expand All @@ -241,6 +245,7 @@ use std::net::IpAddr;

use figment::providers::{Env, Format, Serialized, Toml};
use figment::Figment;
use logging::Logging;
use serde::{Deserialize, Serialize};

use self::core::Core;
Expand All @@ -258,8 +263,9 @@ const CONFIG_OVERRIDE_SEPARATOR: &str = "__";
/// Core configuration for the tracker.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Configuration {
/// Logging configuration
pub logging: Logging,
/// Core configuration.
#[serde(flatten)]
pub core: Core,
/// The list of UDP trackers the tracker is running. Each UDP tracker
/// represents a UDP server that the tracker is running and it has its own
Expand All @@ -278,6 +284,7 @@ pub struct Configuration {
impl Default for Configuration {
fn default() -> Self {
Self {
logging: Logging::default(),
core: Core::default(),
udp_trackers: vec![UdpTracker::default()],
http_trackers: vec![HttpTracker::default()],
Expand Down Expand Up @@ -365,7 +372,10 @@ mod tests {

#[cfg(test)]
fn default_config_toml() -> String {
let config = r#"log_level = "info"
let config = r#"[logging]
log_level = "info"
[core]
mode = "public"
db_driver = "Sqlite3"
db_path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down
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.core.log_level = Some(LogLevel::Off); // Change to `debug` for tests debugging
config.logging.log_level = Some(LogLevel::Off); // Change to `debug` for tests debugging

// Ephemeral socket address for API
let api_port = 0u16;
Expand Down
3 changes: 3 additions & 0 deletions share/default/config/tracker.udp.benchmarking.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[logging]
log_level = "error"

[core]
remove_peerless_torrents = false
tracker_usage_statistics = false

Expand Down
3 changes: 3 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@
//! You can control the behavior of this module with the module settings:
//!
//! ```toml
//! [logging]
//! log_level = "debug"
//!
//! [core]
//! mode = "public"
//! db_driver = "Sqlite3"
//! db_path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,15 @@
//! The default configuration is:
//!
//! ```toml
//! [logging]
//! log_level = "info"
//!
//! [core]
//! announce_interval = 120
//! db_driver = "Sqlite3"
//! db_path = "./storage/tracker/lib/database/sqlite3.db"
//! external_ip = "0.0.0.0"
//! inactive_peer_cleanup_interval = 600
//! log_level = "info"
//! max_peer_timeout = 900
//! min_announce_interval = 120
//! mode = "public"
Expand Down

0 comments on commit 60369da

Please sign in to comment.