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 UTCYYYY-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.logto a timestamped file, then prune old archives. Call this BEFORE the appender opens a freshlatest.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) andwrite_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.
versionis passed in by the caller becauseenv!("CARGO_PKG_VERSION")here would resolve toutils, not the app.