Set up logging properly

Rocket's logger was the only one, so messages from the daemons depended on
it having launched, and most messages bypassed logging with println!.

- Install env_logger at startup: level from log.level (LOG_LEVEL), with
  RUST_LOG overriding it. Rocket's per-request logs and sqlx's Postgres
  notices are kept to warnings.
- Under systemd, prefix lines with their syslog priority so journald
  records levels (journalctl -p warning works).
- Replace every println! with a log macro at a fitting level.
- Recurring failures are a warning when they start or change, debug while
  they repeat, and an info message when they recover.
- Listenbrainz errors are readable: an unknown user is "Listenbrainz user
  "x" doesn't exist" rather than a JSON decode error, and a period without
  stats yet (204) leaves the playlist alone instead of failing to decode.
  The UI's Refresh shows the same messages.
- Warnings name the playlist or rule they're about.
- Songs missing from the library are debug output, not errors every tick.
- Daemons no longer run twice at startup (interval's first tick is
  immediate), and a failing playlist rule or daemon is logged instead of
  panicking the task.
- Subsonic errors display as messages rather than Debug output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018opPJMJjLWr4RqdG6vuK6p
This commit is contained in:
Claude committed 2026-11-13 21:48:54 +00:00
1 parent e176ddac6c
commit a594c56abc
14 files changed
+436 -67

No files matched your search

+9 -4
View File
@@ -28,7 +28,7 @@ fn db_error(e: sqlx::Error) -> Status {
match e {
sqlx::Error::RowNotFound => Status::NotFound,
e => {
println!("Database error: {:?}", e);
log::error!("Database error: {}", e);
Status::InternalServerError
}
}
@@ -114,7 +114,7 @@ async fn mix(
.get_playlist(&summary.playlist_id)
.await
.map_err(|e| {
println!("Could not load playlist {}: {:?}", summary.playlist_id, e);
log::warn!("Could not load playlist {}: {}", summary.playlist_id, e);
Status::BadGateway
})?
.entry;
@@ -350,7 +350,12 @@ async fn youtube(
.search(&suggestion.artist, &suggestion.title)
.await
.map_err(|e| {
println!("YouTube search failed: {}", e);
log::warn!(
"YouTube search failed for {} - {}: {}",
suggestion.artist,
suggestion.title,
e
);
Status::BadGateway
})?
.ok_or(Status::NotFound)?;
@@ -369,7 +374,7 @@ async fn youtube(
// a cached URL may have expired; fetch a fresh one once
for refresh in [false, true] {
let url = youtube.audio_url(&video_id, refresh).await.map_err(|e| {
println!("Could not get audio for {}: {}", video_id, e);
log::warn!("Could not get audio for YouTube video {}: {}", video_id, e);
Status::BadGateway
})?;
let mut request = youtube.client.get(url);