Skip to main content

Module logs

Module logs 

Source
Expand description

On-disk log file management: per-session rotation, retention, crash reports, and the user-facing “export logs” bundle.

Lives in utils (not kopuz) so the settings UI can trigger an export without depending on the binary crate. The tracing subscriber still lives in kopuz::logging; this module only owns the files it writes to.

Layout under <cache>/logs/:

  • latest.log — the current session (the appender writes here).
  • kopuz-<ts>.log — previous sessions, archived on startup so a restart never erases a crashing run. <ts> is UTC YYYY-MM-DD_HH-MM-SS, which sorts alphabetically == chronologically.
  • crash-<ts>.txt — written only on a panic (message + backtrace + recent log tail + version/OS).

Functions§

export_logs
Bundle the current session log and the most recent crash report (plus a version/OS header) into a single file at dest, for the user to attach to a bug report. Triggered by the settings “Export logs” button.
log_dir
The active log directory, if logging has been initialized.
open_log_dir
Reveal the logs directory in the OS file manager so the user can grab latest.log, the archived sessions, and any crash reports directly. Fire-and-forget — we don’t wait on the spawned file manager.
rotate_session_log
Archive the previous session’s latest.log to a timestamped file, then prune old archives. Call this BEFORE the appender opens a fresh latest.log, so the crashing session survives a restart instead of being overwritten.
set_log_dir
Record the active log directory so export_logs (called from the UI) and write_crash_report (called from the panic hook) can find it.
timestamp
UTC YYYY-MM-DD_HH-MM-SS — filename-safe (no colons) and sorts lexicographically in chronological order.
write_crash_report
Write a crash report from the panic hook. Returns the path written. version is passed in by the caller because env!("CARGO_PKG_VERSION") here would resolve to utils, not the app.