Added the log level
CI / check (push) Successful in 1m10s
CI / docker (push) Successful in 3m11s

This commit is contained in:
Connor Johnstone
2026-03-22 13:05:10 -04:00
parent 88b280c2b2
commit 763774ac1e
3 changed files with 28 additions and 7 deletions
+9
View File
@@ -44,6 +44,10 @@ pub struct AppConfig {
#[serde(default)]
pub musicbrainz: MusicBrainzConfig,
/// Log level: "error", "warn", "info", "debug", "trace". Default: "info".
#[serde(default = "default_log_level")]
pub log_level: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -219,6 +223,7 @@ impl Default for AppConfig {
scheduling: SchedulingConfig::default(),
subsonic: SubsonicConfig::default(),
musicbrainz: MusicBrainzConfig::default(),
log_level: default_log_level(),
}
}
}
@@ -279,6 +284,10 @@ impl Default for MetadataConfig {
}
}
fn default_log_level() -> String {
"info".to_string()
}
fn default_library_path() -> PathBuf {
dirs::audio_dir().unwrap_or_else(|| PathBuf::from("~/Music"))
}
+18 -6
View File
@@ -56,18 +56,30 @@ async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
// Load config early so we can use log_level from it
let mut config = AppConfig::load(cli.config.as_deref());
// CLI -v flags override config log_level
let filter = match cli.verbose {
0 => "info,shanty=info,shanty_web=info",
1 => "info,shanty=debug,shanty_web=debug",
_ => "debug,shanty=trace,shanty_web=trace",
0 => {
// Use config log_level
let level = config.log_level.to_lowercase();
match level.as_str() {
"error" => "error".to_string(),
"warn" => "warn".to_string(),
"debug" => "debug,shanty=debug,shanty_web=debug".to_string(),
"trace" => "trace,shanty=trace,shanty_web=trace".to_string(),
_ => "info,shanty=info,shanty_web=info".to_string(),
}
}
1 => "info,shanty=debug,shanty_web=debug".to_string(),
_ => "debug,shanty=trace,shanty_web=trace".to_string(),
};
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(filter)),
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&filter)),
)
.init();
let mut config = AppConfig::load(cli.config.as_deref());
if let Some(port) = cli.port {
config.web.port = port;
}