From a310147ebbd6e0108a4daf36f6302d92e786c429 Mon Sep 17 00:00:00 2001 From: Heorhii Azarov Date: Thu, 26 Dec 2024 12:36:06 +0200 Subject: [PATCH] Change log file size and name --- node-lib/src/options.rs | 1 - node-lib/src/runner.rs | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/node-lib/src/options.rs b/node-lib/src/options.rs index 73dab2514..a6900b66c 100644 --- a/node-lib/src/options.rs +++ b/node-lib/src/options.rs @@ -91,7 +91,6 @@ pub struct RunOptions { /// Log to a file #[clap(long, action = clap::ArgAction::Set)] - #[arg(hide = true)] pub log_to_file: Option, /// Minimum number of connected peers to enable block production. diff --git a/node-lib/src/runner.rs b/node-lib/src/runner.rs index cbc4c0880..ee9ecef2b 100644 --- a/node-lib/src/runner.rs +++ b/node-lib/src/runner.rs @@ -49,7 +49,7 @@ use crate::{ }; const LOCK_FILE_NAME: &str = ".lock"; -const LOG_FILE_NAME: &str = "mintlayer.log"; +const DEFAULT_LOG_FILE_NAME: &str = "mintlayer.log"; pub enum NodeSetupResult { Node(Node), @@ -266,10 +266,19 @@ pub async fn setup(options: Options) -> Result { // Init logging if run_options.log_to_file.is_some_and(|log_to_file| log_to_file) { + let log_file_name = std::env::current_exe().map_or_else( + |_| DEFAULT_LOG_FILE_NAME.to_owned(), + |exe| { + exe.as_path().file_stem().and_then(|stem| stem.to_str()).map_or_else( + || DEFAULT_LOG_FILE_NAME.to_owned(), + |s| format!("{}.log", s.to_owned()), + ) + }, + ); let log_file = FileRotate::new( - data_dir.join(format!("logs/{}", LOG_FILE_NAME)), - AppendCount::new(2), // total 3 file - ContentLimit::Bytes(100_000_000), // 100MB each + data_dir.join(format!("logs/{}", log_file_name)), + AppendCount::new(13), // total 14 files + ContentLimit::Bytes(10_000_000), // 10MB each Compression::None, #[cfg(unix)] None,