Skip to content

Commit

Permalink
Change log file size and name
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Dec 26, 2024
1 parent 77e9de8 commit a310147
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 0 additions & 1 deletion node-lib/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,

/// Minimum number of connected peers to enable block production.
Expand Down
17 changes: 13 additions & 4 deletions node-lib/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -266,10 +266,19 @@ pub async fn setup(options: Options) -> Result<NodeSetupResult> {

// 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,
Expand Down

0 comments on commit a310147

Please sign in to comment.