From 164094c42f8e1de454f86265011a9954e68e403d Mon Sep 17 00:00:00 2001 From: Mo8it Date: Thu, 23 Feb 2023 17:17:25 +0100 Subject: [PATCH] Document logging --- src/config.rs | 1 + src/logging.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/config.rs b/src/config.rs index 598d531..e474e31 100644 --- a/src/config.rs +++ b/src/config.rs @@ -67,6 +67,7 @@ pub struct Config { } impl Config { + /// Parses the configuration from the config path in the environment variable. pub fn build() -> Result { // The environment variable with the path to the config file. let config_file_var = "CF_CONFIG_FILE"; diff --git a/src/logging.rs b/src/logging.rs index f1e5fec..b98d464 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -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)