From f94bbcd4b88af91e27dc9ab5ebfe0a024376bbb1 Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Thu, 14 Nov 2024 19:09:48 +0200 Subject: [PATCH] Make log creation be configurable For now each latte usage creates a log file. And frequent small usages make it generate a lot of garbage log files. So, make it's creation be configurable and disable it by default. --- src/config.rs | 6 +++++- src/main.rs | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 778dd47..464185c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -490,7 +490,7 @@ pub struct RunCommand { #[clap(long("tag"), value_delimiter = ',')] pub tags: Vec, - /// Wether to generate final report or not. If disabled (default) then memory consumption will + /// Whether to generate final report or not. If disabled (default) then memory consumption will /// be static, otherwise it will leak linearly storing samples info for a final report /// calculation. #[clap(long("generate-report"), required = false)] @@ -706,6 +706,10 @@ pub struct AppConfig { #[clap(long("log-dir"), env("LATTE_LOG_DIR"), default_value = ".")] pub log_dir: PathBuf, + /// Whether to create log file and write to it or not. + #[clap(long("enable-logging"), required = false)] + pub enable_logging: bool, + #[clap(subcommand)] pub command: Command, } diff --git a/src/main.rs b/src/main.rs index 5e8eb25..a5a8877 100644 --- a/src/main.rs +++ b/src/main.rs @@ -563,12 +563,16 @@ fn run_id() -> String { fn main() { let run_id = run_id(); let config = AppConfig::parse(); - let _guard = match setup_logging(run_id.as_str(), &config) { - Ok(guard) => guard, - Err(e) => { - eprintln!("error: {e}"); - exit(1); + let _guard = if config.enable_logging { + match setup_logging(run_id.as_str(), &config) { + Ok(guard) => Some(guard), + Err(e) => { + eprintln!("error: {e}"); + exit(1); + } } + } else { + None }; let command = config.command;