mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files * rustfmt * use a constant instead of multiple 32 * rustfmt
This commit is contained in:
parent
7fd2970971
commit
699d85a799
3 changed files with 19 additions and 2 deletions
|
@ -516,6 +516,14 @@ fn comments() -> HashMap<String, String> {
|
|||
.to_string(),
|
||||
);
|
||||
|
||||
retval.insert(
|
||||
"log_max_files".to_string(),
|
||||
"
|
||||
#maximum count of the log files to rotate over
|
||||
"
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
retval
|
||||
}
|
||||
|
||||
|
|
|
@ -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<LoggingConfig>) {
|
|||
let filter = Box::new(ThresholdFilter::new(level_file));
|
||||
let file: Box<dyn Append> = {
|
||||
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);
|
||||
|
||||
|
|
|
@ -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<u64>,
|
||||
/// Number of the log files to rotate over (optional)
|
||||
pub log_max_files: Option<u32>,
|
||||
/// Whether the tui is running (optional)
|
||||
pub tui_running: Option<bool>,
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue