From 611a0b4a87ff1d456662ecf2f02a6f158728eee7 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Tue, 14 Jul 2026 23:26:53 -0700 Subject: [PATCH 1/2] feat(log): remove --log-to-file and log to file if --log-dir is set Signed-off-by: Changyuan Lyu --- alioth-cli/src/main.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/alioth-cli/src/main.rs b/alioth-cli/src/main.rs index 4f27d2c7..d2d318f2 100644 --- a/alioth-cli/src/main.rs +++ b/alioth-cli/src/main.rs @@ -44,11 +44,7 @@ struct Cli { /// If not set, environment variable $RUST_LOG is used. pub log_spec: Option, - /// Log to file instead of STDERR. - #[arg(long)] - pub log_to_file: bool, - - /// Path to a directory where the log file is stored. + /// Path to a directory where the log file is stored, otherwise log to STDERR. #[arg(long, value_name = "PATH")] pub log_dir: Option>, @@ -58,20 +54,18 @@ struct Cli { fn main() -> Result<(), Box> { let cli = Cli::parse(); - let logger = if let Some(ref spec) = cli.log_spec { + let mut logger = if let Some(ref spec) = cli.log_spec { Logger::try_with_str(spec) } else { Logger::try_with_env_or_str("warn") }?; - let logger = if cli.log_to_file { - logger.log_to_file( + if let Some(log_dir) = cli.log_dir { + logger = logger.log_to_file( FileSpec::default() .suppress_timestamp() - .o_directory(cli.log_dir), - ) - } else { - logger - }; + .directory(log_dir), + ); + } let _handle = logger.start()?; log::debug!( "{} {} started...", From a233e11f06a878db5e4766746de6ee98eb9d56c0 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Tue, 14 Jul 2026 23:27:01 -0700 Subject: [PATCH 2/2] feat(log): add --log-file flag to specify log file name Signed-off-by: Changyuan Lyu --- alioth-cli/src/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/alioth-cli/src/main.rs b/alioth-cli/src/main.rs index d2d318f2..d1e6f587 100644 --- a/alioth-cli/src/main.rs +++ b/alioth-cli/src/main.rs @@ -48,6 +48,11 @@ struct Cli { #[arg(long, value_name = "PATH")] pub log_dir: Option>, + /// Name of the log file, if logging to a directory is enabled. + /// If not set, a default name is used. + #[arg(long, value_name = "NAME", requires = "log_dir")] + pub log_file: Option>, + #[command(subcommand)] pub cmd: Command, } @@ -60,11 +65,12 @@ fn main() -> Result<(), Box> { Logger::try_with_env_or_str("warn") }?; if let Some(log_dir) = cli.log_dir { - logger = logger.log_to_file( - FileSpec::default() - .suppress_timestamp() - .directory(log_dir), - ); + let spec = if let Some(name) = cli.log_file { + FileSpec::try_from(log_dir.join(&*name))? + } else { + FileSpec::default().directory(log_dir) + }; + logger = logger.log_to_file(spec); } let _handle = logger.start()?; log::debug!(