Skip to content

Commit af61e20

Browse files
committed
feat: [torrust#936] rename config value log_level to threshold
From: ```toml [logging] log_level = "info" ``` To: ```toml [logging] threshold = "info" ``` Threshold represetns better the concept since this value is the security level at which the app stops collecting logs, meaning it filters out logs with a lower security level.
1 parent b66adcc commit af61e20

File tree

11 files changed

+53
-52
lines changed

11 files changed

+53
-52
lines changed

docs/benchmarking.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ cargo build --release -p aquatic_udp_load_test
2626

2727
### Run UDP load test
2828

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

3131
```toml
3232
[logging]
33-
log_level = "error"
33+
threshold = "error"
3434

3535
[[udp_trackers]]
3636
bind_address = "0.0.0.0:6969"
@@ -97,7 +97,7 @@ Announce responses per info hash:
9797
- p100: 361
9898
```
9999

100-
> IMPORTANT: The performance of the Torrust UDP Tracker is drastically decreased with these log levels: `info`, `debug`, `trace`.
100+
> IMPORTANT: The performance of the Torrust UDP Tracker is drastically decreased with these log threshold: `info`, `debug`, `trace`.
101101
102102
```output
103103
Requests out: 40719.21/second
@@ -161,11 +161,11 @@ Announce responses per info hash:
161161

162162
#### Torrust-Actix UDP Tracker
163163

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

166166
```toml
167167
[logging]
168-
log_level = "error"
168+
threshold = "error"
169169

170170
[[udp_trackers]]
171171
bind_address = "0.0.0.0:6969"

packages/configuration/src/lib.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub type HttpApi = v2::tracker_api::HttpApi;
4141
pub type HttpTracker = v2::http_tracker::HttpTracker;
4242
pub type UdpTracker = v2::udp_tracker::UdpTracker;
4343
pub type Database = v2::database::Database;
44+
pub type Threshold = v2::logging::Threshold;
4445

4546
pub type AccessTokens = HashMap<String, String>;
4647

@@ -241,20 +242,3 @@ impl TslConfig {
241242
Utf8PathBuf::new()
242243
}
243244
}
244-
245-
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
246-
#[serde(rename_all = "lowercase")]
247-
pub enum LogLevel {
248-
/// A level lower than all log levels.
249-
Off,
250-
/// Corresponds to the `Error` log level.
251-
Error,
252-
/// Corresponds to the `Warn` log level.
253-
Warn,
254-
/// Corresponds to the `Info` log level.
255-
Info,
256-
/// Corresponds to the `Debug` log level.
257-
Debug,
258-
/// Corresponds to the `Trace` log level.
259-
Trace,
260-
}
+22-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::LogLevel;
4-
53
#[allow(clippy::struct_excessive_bools)]
64
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
75
pub struct Logging {
86
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
97
/// `Debug` and `Trace`. Default is `Info`.
10-
#[serde(default = "Logging::default_log_level")]
11-
pub log_level: LogLevel,
8+
#[serde(default = "Logging::default_threshold")]
9+
pub threshold: Threshold,
1210
}
1311

1412
impl Default for Logging {
1513
fn default() -> Self {
1614
Self {
17-
log_level: Self::default_log_level(),
15+
threshold: Self::default_threshold(),
1816
}
1917
}
2018
}
2119

2220
impl Logging {
23-
fn default_log_level() -> LogLevel {
24-
LogLevel::Info
21+
fn default_threshold() -> Threshold {
22+
Threshold::Info
2523
}
2624
}
25+
26+
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
27+
#[serde(rename_all = "lowercase")]
28+
pub enum Threshold {
29+
/// A threshold lower than all security levels.
30+
Off,
31+
/// Corresponds to the `Error` security level.
32+
Error,
33+
/// Corresponds to the `Warn` security level.
34+
Warn,
35+
/// Corresponds to the `Info` security level.
36+
Info,
37+
/// Corresponds to the `Debug` security level.
38+
Debug,
39+
/// Corresponds to the `Trace` security level.
40+
Trace,
41+
}

packages/configuration/src/v2/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
//!
197197
//! ```toml
198198
//! [logging]
199-
//! log_level = "info"
199+
//! threshold = "info"
200200
//!
201201
//! [core]
202202
//! inactive_peer_cleanup_interval = 600
@@ -379,7 +379,7 @@ mod tests {
379379
#[cfg(test)]
380380
fn default_config_toml() -> String {
381381
let config = r#"[logging]
382-
log_level = "info"
382+
threshold = "info"
383383
384384
[core]
385385
inactive_peer_cleanup_interval = 600

packages/test-helpers/src/configuration.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::env;
33
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
44

5-
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, LogLevel, UdpTracker};
5+
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, Threshold, UdpTracker};
66

77
use crate::random;
88

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

2929
let mut config = Configuration::default();
3030

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

3333
// Ephemeral socket address for API
3434
let api_port = 0u16;

share/default/config/tracker.udp.benchmarking.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[logging]
2-
log_level = "error"
2+
threshold = "error"
33

44
[core]
55
remove_peerless_torrents = false

src/bootstrap/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn initialize_tracker(config: &Configuration) -> Tracker {
6868
tracker_factory(config)
6969
}
7070

71-
/// It initializes the log level, format and channel.
71+
/// It initializes the log threshold, format and channel.
7272
///
7373
/// See [the logging setup](crate::bootstrap::logging::setup) for more info about logging.
7474
pub fn initialize_logging(config: &Configuration) {

src/bootstrap/logging.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Setup for the application logging.
22
//!
3-
//! It redirects the log info to the standard output with the log level defined in the configuration.
3+
//! It redirects the log info to the standard output with the log threshold
4+
//! defined in the configuration.
45
//!
56
//! - `Off`
67
//! - `Error`
@@ -12,15 +13,16 @@
1213
//! Refer to the [configuration crate documentation](https://docs.rs/torrust-tracker-configuration) to know how to change log settings.
1314
use std::sync::Once;
1415

15-
use torrust_tracker_configuration::{Configuration, LogLevel};
16+
use torrust_tracker_configuration::{Configuration, Threshold};
1617
use tracing::info;
1718
use tracing::level_filters::LevelFilter;
1819

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

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

2527
if tracing_level == LevelFilter::OFF {
2628
return;
@@ -31,14 +33,14 @@ pub fn setup(cfg: &Configuration) {
3133
});
3234
}
3335

34-
fn map_to_tracing_level_filter(log_level: &LogLevel) -> LevelFilter {
35-
match log_level {
36-
LogLevel::Off => LevelFilter::OFF,
37-
LogLevel::Error => LevelFilter::ERROR,
38-
LogLevel::Warn => LevelFilter::WARN,
39-
LogLevel::Info => LevelFilter::INFO,
40-
LogLevel::Debug => LevelFilter::DEBUG,
41-
LogLevel::Trace => LevelFilter::TRACE,
36+
fn map_to_tracing_level_filter(threshold: &Threshold) -> LevelFilter {
37+
match threshold {
38+
Threshold::Off => LevelFilter::OFF,
39+
Threshold::Error => LevelFilter::ERROR,
40+
Threshold::Warn => LevelFilter::WARN,
41+
Threshold::Info => LevelFilter::INFO,
42+
Threshold::Debug => LevelFilter::DEBUG,
43+
Threshold::Trace => LevelFilter::TRACE,
4244
}
4345
}
4446

src/console/ci/e2e/logs_parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::servers::http::HTTP_TRACKER_LOG_TARGET;
77
use crate::servers::logging::STARTED_ON;
88
use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
99

10-
const INFO_LOG_LEVEL: &str = "INFO";
10+
const INFO_THRESHOLD: &str = "INFO";
1111

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

77-
if !line.contains(INFO_LOG_LEVEL) {
77+
if !line.contains(INFO_THRESHOLD) {
7878
continue;
7979
};
8080

src/core/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
//!
314314
//! ```toml
315315
//! [logging]
316-
//! log_level = "debug"
316+
//! threshold = "debug"
317317
//!
318318
//! [core]
319319
//! inactive_peer_cleanup_interval = 600

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
//!
169169
//! ```toml
170170
//! [logging]
171-
//! log_level = "info"
171+
//! threshold = "info"
172172
//!
173173
//! [core]
174174
//! inactive_peer_cleanup_interval = 600

0 commit comments

Comments
 (0)