Document logging

This commit is contained in:
Mo 2023-02-23 17:17:25 +01:00
parent 17d1606ae6
commit 164094c42f
2 changed files with 6 additions and 0 deletions

View file

@ -67,6 +67,7 @@ pub struct Config {
}
impl Config {
/// Parses the configuration from the config path in the environment variable.
pub fn build() -> Result<Self> {
// The environment variable with the path to the config file.
let config_file_var = "CF_CONFIG_FILE";

View file

@ -9,23 +9,28 @@ use tracing_subscriber::{
Layer,
};
/// Initializes the logger.
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(
UtcOffset::from_hms(utc_offset_hours, utc_offset_minutes, 0)
.context("Failed to set the time offset from the given utc_hours_offset!")?,
Rfc3339,
);
// Use the DEBUG level in debug builds.
let stdout_level_filter = if cfg!(debug_assertions) {
LevelFilter::DEBUG
} else {
LevelFilter::INFO
};
// Stdout logger.
let stdout_layer = fmt::layer()
.with_ansi(true)
.with_timer(timer.clone())
.with_filter(stdout_level_filter);
// Log file.
let log_file = OpenOptions::new()
.create(true)
.append(true)