feat: logging to log file

This commit is contained in:
Michel de Graaf
2025-11-18 15:49:53 +01:00
parent 4c6d7c6850
commit 2ba48663e4
3 changed files with 115 additions and 4 deletions
+4
View File
@@ -1,4 +1,5 @@
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(
@@ -32,6 +33,9 @@ pub struct Cli {
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
#[arg(long, env = "LOG_FILE", help = "Write logs to file instead of stderr")]
pub log_file: Option<PathBuf>,
#[command(subcommand)]
pub command: Option<Commands>,
+5
View File
@@ -29,6 +29,11 @@ fn main() -> Result<()> {
};
env::set_var("LOG_LEVEL", log_level);
// Set LOG_FILE env var if provided via CLI
if let Some(log_file) = &cli.log_file {
env::set_var("LOG_FILE", log_file.to_string_lossy().to_string());
}
let username = cli.username
.ok_or_else(|| color_eyre::eyre::eyre!("Username required: use --username or set SOULSEEK_USERNAME env var"))?;