Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config overhaul: rename log_level to threshold #942

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ cargo build --release -p aquatic_udp_load_test

### Run UDP load test

Run the tracker with UDP service enabled and other services disabled and set log level to `error`.
Run the tracker with UDP service enabled and other services disabled and set log threshold to `error`.

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

[[udp_trackers]]
bind_address = "0.0.0.0:6969"
Expand Down Expand Up @@ -97,7 +97,7 @@ Announce responses per info hash:
- p100: 361
```

> IMPORTANT: The performance of the Torrust UDP Tracker is drastically decreased with these log levels: `info`, `debug`, `trace`.
> IMPORTANT: The performance of the Torrust UDP Tracker is drastically decreased with these log threshold: `info`, `debug`, `trace`.

```output
Requests out: 40719.21/second
Expand Down Expand Up @@ -161,11 +161,11 @@ Announce responses per info hash:

#### Torrust-Actix UDP Tracker

Run the tracker with UDP service enabled and other services disabled and set log level to `error`.
Run the tracker with UDP service enabled and other services disabled and set log threshold to `error`.

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

[[udp_trackers]]
bind_address = "0.0.0.0:6969"
Expand Down
18 changes: 1 addition & 17 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub type HttpApi = v2::tracker_api::HttpApi;
pub type HttpTracker = v2::http_tracker::HttpTracker;
pub type UdpTracker = v2::udp_tracker::UdpTracker;
pub type Database = v2::database::Database;
pub type Threshold = v2::logging::Threshold;

pub type AccessTokens = HashMap<String, String>;

Expand Down Expand Up @@ -241,20 +242,3 @@ impl TslConfig {
Utf8PathBuf::new()
}
}

#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
#[serde(rename_all = "lowercase")]
pub enum LogLevel {
/// A level lower than all log levels.
Off,
/// Corresponds to the `Error` log level.
Error,
/// Corresponds to the `Warn` log level.
Warn,
/// Corresponds to the `Info` log level.
Info,
/// Corresponds to the `Debug` log level.
Debug,
/// Corresponds to the `Trace` log level.
Trace,
}
29 changes: 22 additions & 7 deletions packages/configuration/src/v2/logging.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
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: LogLevel,
#[serde(default = "Logging::default_threshold")]

Check warning on line 8 in packages/configuration/src/v2/logging.rs

View check run for this annotation

Codecov / codecov/patch

packages/configuration/src/v2/logging.rs#L8

Added line #L8 was not covered by tests
pub threshold: Threshold,
}

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

impl Logging {
fn default_log_level() -> LogLevel {
LogLevel::Info
fn default_threshold() -> Threshold {
Threshold::Info
}
}

#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Threshold {
/// A threshold lower than all security levels.
Off,
/// Corresponds to the `Error` security level.
Error,
/// Corresponds to the `Warn` security level.
Warn,
/// Corresponds to the `Info` security level.
Info,
/// Corresponds to the `Debug` security level.
Debug,
/// Corresponds to the `Trace` security level.
Trace,
}
4 changes: 2 additions & 2 deletions packages/configuration/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
//!
//! ```toml
//! [logging]
//! log_level = "info"
//! threshold = "info"
//!
//! [core]
//! inactive_peer_cleanup_interval = 600
Expand Down Expand Up @@ -379,7 +379,7 @@ mod tests {
#[cfg(test)]
fn default_config_toml() -> String {
let config = r#"[logging]
log_level = "info"
threshold = "info"

[core]
inactive_peer_cleanup_interval = 600
Expand Down
6 changes: 3 additions & 3 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::env;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};

use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, LogLevel, UdpTracker};
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, Threshold, UdpTracker};

use crate::random;

Expand All @@ -14,7 +14,7 @@ use crate::random;
/// > **NOTICE**: Port 0 is used for ephemeral ports, which means that the OS
/// > will assign a random free port for the tracker to use.
///
/// > **NOTICE**: You can change the log level to `debug` to see the logs of the
/// > **NOTICE**: You can change the log threshold to `debug` to see the logs of the
/// > tracker while running the tests. That can be particularly useful when
/// > debugging tests.
///
Expand All @@ -28,7 +28,7 @@ pub fn ephemeral() -> Configuration {

let mut config = Configuration::default();

config.logging.log_level = LogLevel::Off; // Change to `debug` for tests debugging
config.logging.threshold = Threshold::Off; // Change to `debug` for tests debugging

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

[core]
remove_peerless_torrents = false
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn initialize_tracker(config: &Configuration) -> Tracker {
tracker_factory(config)
}

/// It initializes the log level, format and channel.
/// It initializes the log threshold, format and channel.
///
/// See [the logging setup](crate::bootstrap::logging::setup) for more info about logging.
pub fn initialize_logging(config: &Configuration) {
Expand Down
26 changes: 14 additions & 12 deletions src/bootstrap/logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Setup for the application logging.
//!
//! It redirects the log info to the standard output with the log level defined in the configuration.
//! It redirects the log info to the standard output with the log threshold
//! defined in the configuration.
//!
//! - `Off`
//! - `Error`
Expand All @@ -12,15 +13,16 @@
//! Refer to the [configuration crate documentation](https://docs.rs/torrust-tracker-configuration) to know how to change log settings.
use std::sync::Once;

use torrust_tracker_configuration::{Configuration, LogLevel};
use torrust_tracker_configuration::{Configuration, Threshold};
use tracing::info;
use tracing::level_filters::LevelFilter;

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

/// It redirects the log info to the standard output with the log level defined in the configuration
/// It redirects the log info to the standard output with the log threshold
/// defined in the configuration.
pub fn setup(cfg: &Configuration) {
let tracing_level = map_to_tracing_level_filter(&cfg.logging.log_level);
let tracing_level = map_to_tracing_level_filter(&cfg.logging.threshold);

if tracing_level == LevelFilter::OFF {
return;
Expand All @@ -31,14 +33,14 @@
});
}

fn map_to_tracing_level_filter(log_level: &LogLevel) -> LevelFilter {
match log_level {
LogLevel::Off => LevelFilter::OFF,
LogLevel::Error => LevelFilter::ERROR,
LogLevel::Warn => LevelFilter::WARN,
LogLevel::Info => LevelFilter::INFO,
LogLevel::Debug => LevelFilter::DEBUG,
LogLevel::Trace => LevelFilter::TRACE,
fn map_to_tracing_level_filter(threshold: &Threshold) -> LevelFilter {
match threshold {
Threshold::Off => LevelFilter::OFF,
Threshold::Error => LevelFilter::ERROR,
Threshold::Warn => LevelFilter::WARN,
Threshold::Info => LevelFilter::INFO,
Threshold::Debug => LevelFilter::DEBUG,
Threshold::Trace => LevelFilter::TRACE,

Check warning on line 43 in src/bootstrap/logging.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/logging.rs#L39-L43

Added lines #L39 - L43 were not covered by tests
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/console/ci/e2e/logs_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::servers::http::HTTP_TRACKER_LOG_TARGET;
use crate::servers::logging::STARTED_ON;
use crate::servers::udp::UDP_TRACKER_LOG_TARGET;

const INFO_LOG_LEVEL: &str = "INFO";
const INFO_THRESHOLD: &str = "INFO";

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct RunningServices {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl RunningServices {
for line in logs.lines() {
let clean_line = ansi_escape_re.replace_all(line, "");

if !line.contains(INFO_LOG_LEVEL) {
if !line.contains(INFO_THRESHOLD) {
continue;
};

Expand Down
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
//!
//! ```toml
//! [logging]
//! log_level = "debug"
//! threshold = "debug"
//!
//! [core]
//! inactive_peer_cleanup_interval = 600
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
//!
//! ```toml
//! [logging]
//! log_level = "info"
//! threshold = "info"
//!
//! [core]
//! inactive_peer_cleanup_interval = 600
Expand Down
Loading