forked from Fraunhofer-AISEC/ids-clearing-house-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ch-app): Setup tracing as logger and replace rocket as logger; s…
…etup config
- Loading branch information
1 parent
f2bf55f
commit 356665a
Showing
8 changed files
with
114 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
#[derive(Debug, serde::Deserialize)] | ||
pub(crate) struct CHConfig { | ||
pub(crate) process_database_url: String, | ||
pub(crate) keyring_database_url: String, | ||
pub(crate) document_database_url: String, | ||
pub(crate) clear_db: bool, | ||
#[serde(default)] | ||
pub(crate) log_level: Option<LogLevel>, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
#[serde(rename_all = "UPPERCASE")] | ||
pub(crate) enum LogLevel { | ||
Trace, | ||
Debug, | ||
Info, | ||
Warn, | ||
Error, | ||
} | ||
|
||
impl Into<tracing::Level> for LogLevel { | ||
fn into(self) -> tracing::Level { | ||
match self { | ||
LogLevel::Trace => tracing::Level::TRACE, | ||
LogLevel::Debug => tracing::Level::DEBUG, | ||
LogLevel::Info => tracing::Level::INFO, | ||
LogLevel::Warn => tracing::Level::WARN, | ||
LogLevel::Error => tracing::Level::ERROR, | ||
} | ||
} | ||
} | ||
|
||
impl ToString for LogLevel { | ||
fn to_string(&self) -> String { | ||
match self { | ||
LogLevel::Trace => String::from("TRACE"), | ||
LogLevel::Debug => String::from("DEBUG"), | ||
LogLevel::Info => String::from("INFO"), | ||
LogLevel::Warn => String::from("WARN"), | ||
LogLevel::Error => String::from("ERROR"), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn read_config() -> CHConfig { | ||
let conf = config::Config::builder() | ||
.add_source(config::File::with_name("config.toml")) | ||
.add_source(config::Environment::with_prefix("CH_APP_")) | ||
.build() | ||
.expect("Failure to read configuration! Exiting..."); | ||
|
||
let conf: CHConfig = conf.try_deserialize().expect("Failure to read configuration! Exiting..."); | ||
tracing::trace!(config = ?conf, "Config read"); | ||
|
||
conf | ||
} | ||
|
||
pub(crate) fn configure_logging(log_level: Option<LogLevel>) { | ||
if std::env::var("RUST_LOG").is_err() { | ||
if let Some(level) = log_level { | ||
std::env::set_var("RUST_LOG", level.to_string()); | ||
} | ||
} | ||
|
||
// setup logging | ||
tracing_subscriber::fmt() | ||
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) | ||
.init(); | ||
} |
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