diff --git a/config/src/comments.rs b/config/src/comments.rs index e5b7408f6d..0f35307457 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -516,6 +516,14 @@ fn comments() -> HashMap { .to_string(), ); + retval.insert( + "log_max_files".to_string(), + " +#maximum count of the log files to rotate over +" + .to_string(), + ); + retval } diff --git a/util/src/logger.rs b/util/src/logger.rs index e5048267cc..322098f1c9 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -18,7 +18,7 @@ use std::ops::Deref; use backtrace::Backtrace; use std::{panic, thread}; -use crate::types::{LogLevel, LoggingConfig}; +use crate::types::{self, LogLevel, LoggingConfig}; use log::{LevelFilter, Record}; use log4rs; @@ -124,8 +124,11 @@ pub fn init_logger(config: Option) { let filter = Box::new(ThresholdFilter::new(level_file)); let file: Box = { if let Some(size) = c.log_max_size { + let count = c + .log_max_files + .unwrap_or_else(|| types::DEFAULT_ROTATE_LOG_FILES); let roller = FixedWindowRoller::builder() - .build(&format!("{}.{{}}.gz", c.log_file_path), 32) + .build(&format!("{}.{{}}.gz", c.log_file_path), count) .unwrap(); let trigger = SizeTrigger::new(size); diff --git a/util/src/types.rs b/util/src/types.rs index f6505662eb..a7f9c84da6 100644 --- a/util/src/types.rs +++ b/util/src/types.rs @@ -29,6 +29,9 @@ pub enum LogLevel { Trace, } +/// 32 log files to rotate over by default +pub const DEFAULT_ROTATE_LOG_FILES: u32 = 32 as u32; + /// Logging config #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct LoggingConfig { @@ -46,6 +49,8 @@ pub struct LoggingConfig { pub log_file_append: bool, /// Size of the log in bytes to rotate over (optional) pub log_max_size: Option, + /// Number of the log files to rotate over (optional) + pub log_max_files: Option, /// Whether the tui is running (optional) pub tui_running: Option, } @@ -60,6 +65,7 @@ impl Default for LoggingConfig { log_file_path: String::from("grin.log"), log_file_append: true, log_max_size: Some(1024 * 1024 * 16), // 16 megabytes default + log_max_files: Some(DEFAULT_ROTATE_LOG_FILES), tui_running: None, } }