forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [torrust#591] move log_level into a new logging section in config
Old: ```toml log_level = "info" [website] name = "Torrust" ``` New: ```toml [logging] log_level = "info" [website] name = "Torrust" ``` And the value is not Optional anymore. It was a Optional<LogLevel> but when it was None it defaulted to LogLevel::Info. In practice that means is mandatory but with the `Info` default value.
- Loading branch information
1 parent
12010f1
commit 49c964b
Showing
14 changed files
with
117 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
[database] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
[database] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
# Uncomment if you want to enable TSL for development | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
[tracker] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
[tracker] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[logging] | ||
log_level = "info" | ||
|
||
[tracker] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::fmt; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use tracing::level_filters::LevelFilter; | ||
|
||
/// Core configuration for the API | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
pub struct Logging { | ||
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`, `Debug`, `Trace`. | ||
#[serde(default = "Logging::default_log_level")] | ||
pub log_level: LogLevel, | ||
} | ||
|
||
impl Default for Logging { | ||
fn default() -> Self { | ||
Self { | ||
log_level: Logging::default_log_level(), | ||
} | ||
} | ||
} | ||
|
||
impl Logging { | ||
fn default_log_level() -> LogLevel { | ||
LogLevel::Info | ||
} | ||
} | ||
|
||
#[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, | ||
} | ||
|
||
impl Default for LogLevel { | ||
fn default() -> Self { | ||
Self::Info | ||
} | ||
} | ||
|
||
impl fmt::Display for LogLevel { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let display_str = match self { | ||
LogLevel::Off => "off", | ||
LogLevel::Error => "error", | ||
LogLevel::Warn => "warn", | ||
LogLevel::Info => "info", | ||
LogLevel::Debug => "debug", | ||
LogLevel::Trace => "trace", | ||
}; | ||
write!(f, "{display_str}") | ||
} | ||
} | ||
|
||
impl From<LogLevel> for LevelFilter { | ||
fn from(log_level: LogLevel) -> Self { | ||
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, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters