Document logging
This commit is contained in:
parent
17d1606ae6
commit
164094c42f
2 changed files with 6 additions and 0 deletions
|
@ -67,6 +67,7 @@ pub struct Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
/// Parses the configuration from the config path in the environment variable.
|
||||||
pub fn build() -> Result<Self> {
|
pub fn build() -> Result<Self> {
|
||||||
// The environment variable with the path to the config file.
|
// The environment variable with the path to the config file.
|
||||||
let config_file_var = "CF_CONFIG_FILE";
|
let config_file_var = "CF_CONFIG_FILE";
|
||||||
|
|
|
@ -9,23 +9,28 @@ use tracing_subscriber::{
|
||||||
Layer,
|
Layer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Initializes the logger.
|
||||||
pub fn init_logger(log_file: &str, utc_offset_hours: i8, utc_offset_minutes: i8) -> Result<()> {
|
pub fn init_logger(log_file: &str, utc_offset_hours: i8, utc_offset_minutes: i8) -> Result<()> {
|
||||||
|
// Set UTC offset for time formatting.
|
||||||
let timer = OffsetTime::new(
|
let timer = OffsetTime::new(
|
||||||
UtcOffset::from_hms(utc_offset_hours, utc_offset_minutes, 0)
|
UtcOffset::from_hms(utc_offset_hours, utc_offset_minutes, 0)
|
||||||
.context("Failed to set the time offset from the given utc_hours_offset!")?,
|
.context("Failed to set the time offset from the given utc_hours_offset!")?,
|
||||||
Rfc3339,
|
Rfc3339,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Use the DEBUG level in debug builds.
|
||||||
let stdout_level_filter = if cfg!(debug_assertions) {
|
let stdout_level_filter = if cfg!(debug_assertions) {
|
||||||
LevelFilter::DEBUG
|
LevelFilter::DEBUG
|
||||||
} else {
|
} else {
|
||||||
LevelFilter::INFO
|
LevelFilter::INFO
|
||||||
};
|
};
|
||||||
|
// Stdout logger.
|
||||||
let stdout_layer = fmt::layer()
|
let stdout_layer = fmt::layer()
|
||||||
.with_ansi(true)
|
.with_ansi(true)
|
||||||
.with_timer(timer.clone())
|
.with_timer(timer.clone())
|
||||||
.with_filter(stdout_level_filter);
|
.with_filter(stdout_level_filter);
|
||||||
|
|
||||||
|
// Log file.
|
||||||
let log_file = OpenOptions::new()
|
let log_file = OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
|
|
Loading…
Reference in a new issue