Added the log level

This commit is contained in:
Connor Johnstone
2026-03-22 13:05:09 -04:00
parent 3dba620c9b
commit 44c96d125a
3 changed files with 42 additions and 6 deletions

View File

@@ -837,6 +837,27 @@ pub fn settings_page() -> Html {
</div>
</div>
// Logging
<div class="card">
<h3>{ "Logging" }</h3>
<div class="form-group">
<label>{ "Log Level" }</label>
<select onchange={let config = config.clone(); Callback::from(move |e: Event| {
let select: HtmlSelectElement = e.target_unchecked_into();
let mut cfg = (*config).clone().unwrap();
cfg.log_level = select.value();
config.set(Some(cfg));
})}>
{ for [("error", "Error"), ("warn", "Warning"), ("info", "Info"), ("debug", "Debug"), ("trace", "Trace")].iter().map(|(v, label)| html! {
<option value={*v} selected={c.log_level == *v}>{ label }</option>
})}
</select>
<p class="text-muted text-sm" style="margin-top: 0.25rem;">
{ "Requires restart to take effect. CLI flags (-v, -vv) override this setting." }
</p>
</div>
</div>
<button type="submit" class="btn btn-primary">{ "Save Settings" }</button>
</form>
</div>

View File

@@ -402,6 +402,12 @@ pub struct AppConfig {
pub scheduling: SchedulingConfigFe,
#[serde(default)]
pub musicbrainz: MusicBrainzConfigFe,
#[serde(default = "default_log_level")]
pub log_level: String,
}
fn default_log_level() -> String {
"info".into()
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]

View File

@@ -35,18 +35,27 @@ struct Cli {
async fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
let mut config = AppConfig::load(cli.config.as_deref());
let filter = match cli.verbose {
0 => "info,shanty_web=info",
1 => "info,shanty_web=debug",
_ => "debug,shanty_web=trace",
0 => {
let level = config.log_level.to_lowercase();
match level.as_str() {
"error" => "error".to_string(),
"warn" => "warn".to_string(),
"debug" => "debug,shanty_web=debug".to_string(),
"trace" => "trace,shanty_web=trace".to_string(),
_ => "info,shanty_web=info".to_string(),
}
}
1 => "info,shanty_web=debug".to_string(),
_ => "debug,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;
}