Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions alioth-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,34 @@ struct Cli {
/// If not set, environment variable $RUST_LOG is used.
pub log_spec: Option<String>,

/// 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<Box<Path>>,

/// 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<Box<str>>,

#[command(subcommand)]
pub cmd: Command,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
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...",
Expand Down