Added the log level
This commit is contained in:
@@ -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"))
|
||||
}
|
||||
|
||||
+1
-1
Submodule shanty-web updated: 3dba620c9b...44c96d125a
+18
-6
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user