diff --git a/alioth-cli/src/main.rs b/alioth-cli/src/main.rs index 4f27d2c7..d1e6f587 100644 --- a/alioth-cli/src/main.rs +++ b/alioth-cli/src/main.rs @@ -44,34 +44,34 @@ 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>, + /// 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, } 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( - FileSpec::default() - .suppress_timestamp() - .o_directory(cli.log_dir), - ) - } else { - logger - }; + if let Some(log_dir) = cli.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!( "{} {} started...",