Skip to content

Commit df96264

Browse files
committed
feat: [#652] rename config option log_level to threshold
Rename `log_level` to `threshold` ```toml [logging] log_level = "info" ``` ```toml [logging] threshold = "info" ```
1 parent 5e8692b commit df96264

13 files changed

+80
-50
lines changed

share/default/config/index.container.mysql.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
[database]
712
connect_url = "mysql://root:root_secret_password@mysql:3306/torrust_index"

share/default/config/index.container.sqlite3.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
[database]
712
connect_url = "sqlite:///var/lib/torrust/index/database/sqlite3.db?mode=rwc"

share/default/config/index.development.sqlite3.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
# Uncomment if you want to enable TSL for development
712
#[net.tsl]

share/default/config/index.private.e2e.container.sqlite3.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
[tracker]
712
api_url = "http://tracker:1212"

share/default/config/index.public.e2e.container.mysql.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
[tracker]
712
api_url = "http://tracker:1212"

share/default/config/index.public.e2e.container.sqlite3.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
version = "2"
22

33
[logging]
4-
log_level = "info"
4+
#threshold = "off"
5+
#threshold = "error"
6+
#threshold = "warn"
7+
threshold = "info"
8+
#threshold = "debug"
9+
#threshold = "trace"
510

611
[tracker]
712
api_url = "http://tracker:1212"

src/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ pub struct Running {
3939
/// It panics if there is an error connecting to the database.
4040
#[allow(clippy::too_many_lines)]
4141
pub async fn run(configuration: Configuration, api_version: &Version) -> Running {
42-
let log_level = configuration.settings.read().await.logging.log_level.clone();
42+
let threshold = configuration.settings.read().await.logging.threshold.clone();
4343

44-
logging::setup(&log_level);
44+
logging::setup(&threshold);
4545

4646
log_configuration(&configuration).await;
4747

src/bootstrap/logging.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ use std::sync::Once;
1111
use tracing::info;
1212
use tracing::level_filters::LevelFilter;
1313

14-
use crate::config::LogLevel;
14+
use crate::config::Threshold;
1515

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

18-
pub fn setup(log_level: &LogLevel) {
19-
let tracing_level: LevelFilter = log_level.clone().into();
18+
pub fn setup(threshold: &Threshold) {
19+
let tracing_level_filter: LevelFilter = threshold.clone().into();
2020

21-
if tracing_level == LevelFilter::OFF {
21+
if tracing_level_filter == LevelFilter::OFF {
2222
return;
2323
}
2424

2525
INIT.call_once(|| {
26-
tracing_stdout_init(tracing_level, &TraceStyle::Default);
26+
tracing_stdout_init(tracing_level_filter, &TraceStyle::Default);
2727
});
2828
}
2929

src/config/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub type Tracker = v2::tracker::Tracker;
4444
pub type ApiToken = v2::tracker::ApiToken;
4545

4646
pub type Logging = v2::logging::Logging;
47-
pub type LogLevel = v2::logging::LogLevel;
47+
pub type Threshold = v2::logging::Threshold;
4848

4949
pub type Website = v2::website::Website;
5050

@@ -408,7 +408,7 @@ mod tests {
408408
let config = r#"version = "2"
409409
410410
[logging]
411-
log_level = "info"
411+
threshold = "info"
412412
413413
[website]
414414
name = "Torrust"

src/config/v2/logging.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,70 @@ use tracing::level_filters::LevelFilter;
77
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
88
pub struct Logging {
99
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`, `Debug`, `Trace`.
10-
#[serde(default = "Logging::default_log_level")]
11-
pub log_level: LogLevel,
10+
#[serde(default = "Logging::default_threshold")]
11+
pub threshold: Threshold,
1212
}
1313

1414
impl Default for Logging {
1515
fn default() -> Self {
1616
Self {
17-
log_level: Logging::default_log_level(),
17+
threshold: Logging::default_threshold(),
1818
}
1919
}
2020
}
2121

2222
impl Logging {
23-
fn default_log_level() -> LogLevel {
24-
LogLevel::Info
23+
fn default_threshold() -> Threshold {
24+
Threshold::Info
2525
}
2626
}
2727

2828
#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
2929
#[serde(rename_all = "lowercase")]
30-
pub enum LogLevel {
31-
/// A level lower than all log levels.
30+
pub enum Threshold {
31+
/// A level lower than all log security levels.
3232
Off,
33-
/// Corresponds to the `Error` log level.
33+
/// Corresponds to the `Error` log security level.
3434
Error,
35-
/// Corresponds to the `Warn` log level.
35+
/// Corresponds to the `Warn` log security level.
3636
Warn,
37-
/// Corresponds to the `Info` log level.
37+
/// Corresponds to the `Info` log security level.
3838
Info,
39-
/// Corresponds to the `Debug` log level.
39+
/// Corresponds to the `Debug` log security level.
4040
Debug,
41-
/// Corresponds to the `Trace` log level.
41+
/// Corresponds to the `Trace` log security level.
4242
Trace,
4343
}
4444

45-
impl Default for LogLevel {
45+
impl Default for Threshold {
4646
fn default() -> Self {
4747
Self::Info
4848
}
4949
}
5050

51-
impl fmt::Display for LogLevel {
51+
impl fmt::Display for Threshold {
5252
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5353
let display_str = match self {
54-
LogLevel::Off => "off",
55-
LogLevel::Error => "error",
56-
LogLevel::Warn => "warn",
57-
LogLevel::Info => "info",
58-
LogLevel::Debug => "debug",
59-
LogLevel::Trace => "trace",
54+
Threshold::Off => "off",
55+
Threshold::Error => "error",
56+
Threshold::Warn => "warn",
57+
Threshold::Info => "info",
58+
Threshold::Debug => "debug",
59+
Threshold::Trace => "trace",
6060
};
6161
write!(f, "{display_str}")
6262
}
6363
}
6464

65-
impl From<LogLevel> for LevelFilter {
66-
fn from(log_level: LogLevel) -> Self {
67-
match log_level {
68-
LogLevel::Off => LevelFilter::OFF,
69-
LogLevel::Error => LevelFilter::ERROR,
70-
LogLevel::Warn => LevelFilter::WARN,
71-
LogLevel::Info => LevelFilter::INFO,
72-
LogLevel::Debug => LevelFilter::DEBUG,
73-
LogLevel::Trace => LevelFilter::TRACE,
65+
impl From<Threshold> for LevelFilter {
66+
fn from(threshold: Threshold) -> Self {
67+
match threshold {
68+
Threshold::Off => LevelFilter::OFF,
69+
Threshold::Error => LevelFilter::ERROR,
70+
Threshold::Warn => LevelFilter::WARN,
71+
Threshold::Info => LevelFilter::INFO,
72+
Threshold::Debug => LevelFilter::DEBUG,
73+
Threshold::Trace => LevelFilter::TRACE,
7474
}
7575
}
7676
}

src/console/commands/tracker_statistics_importer/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ pub async fn import() {
9090

9191
let configuration = initialize_configuration();
9292

93-
let log_level = configuration.settings.read().await.logging.log_level.clone();
93+
let threshold = configuration.settings.read().await.logging.threshold.clone();
9494

95-
logging::setup(&log_level);
95+
logging::setup(&threshold);
9696

9797
let cfg = Arc::new(configuration);
9898

tests/common/contexts/settings/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Settings {
2727

2828
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
2929
pub struct Logging {
30-
pub log_level: String,
30+
pub threshold: String,
3131
}
3232

3333
#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
@@ -130,7 +130,7 @@ impl From<DomainSettings> for Settings {
130130
impl From<DomainLogging> for Logging {
131131
fn from(logging: DomainLogging) -> Self {
132132
Self {
133-
log_level: logging.log_level.to_string(),
133+
threshold: logging.threshold.to_string(),
134134
}
135135
}
136136
}

tests/environments/isolated.rs

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

33
use tempfile::TempDir;
44
use torrust_index::config;
5-
use torrust_index::config::{LogLevel, FREE_PORT};
5+
use torrust_index::config::{Threshold, FREE_PORT};
66
use torrust_index::web::api::Version;
77
use url::Url;
88

@@ -75,7 +75,7 @@ impl Default for TestEnv {
7575
fn ephemeral(temp_dir: &TempDir) -> config::Settings {
7676
let mut configuration = config::Settings::default();
7777

78-
configuration.logging.log_level = LogLevel::Off; // Change to `debug` for tests debugging
78+
configuration.logging.threshold = Threshold::Off; // Change to `debug` for tests debugging
7979

8080
// Ephemeral API port
8181
configuration.net.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), FREE_PORT);

0 commit comments

Comments
 (0)