Compare commits

...

2 Commits

Author SHA1 Message Date
Connor Johnstone
f87949dc82 Fixed an auto-logging bug 2026-03-22 13:18:23 -04:00
Connor Johnstone
44c96d125a Added the log level 2026-03-22 13:05:09 -04:00
4 changed files with 47 additions and 7 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;
}

View File

@@ -393,7 +393,11 @@ async fn trigger_mb_import(
&format!("Downloading {filename}..."),
);
if let Err(e) =
shanty_data::mb_import::download_dump(filename, &timestamp, &data_dir, |_| {}).await
shanty_data::mb_import::download_dump(filename, &timestamp, &data_dir, |msg| {
tracing::info!("{msg}");
state.tasks.update_progress(&tid, i as u64, 8, msg);
})
.await
{
state
.tasks