mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-25 02:30:15 -06:00
The desktop app's logger (StderrLog in main.rs) wrote to standard error only. A launch from a desktop menu or the Dock has no terminal, so its warnings were lost, and the panic log in the temp folder is gone after a reboot: there was nothing to attach to a bug report. apps/lightcraft/src/logging.rs replaces it (no new dependency): - standard error plus logs/lightcraft.log in the settings folder, next to ui.json (Linux $XDG_CONFIG_HOME/lightcraft/logs, never the library); each launch rotates the previous log to lightcraft.1.log and .2.log, so the log of a run that crashed survives the next start; the file is capped at 16 MiB with one note - records logged before the settings folder is known are buffered (bounded) and written once the file is attached - default levels: info for lightcraft*, warn for everything else; LIGHTCRAFT_LOG=info|debug keeps its old meaning (a test compares it with the old logger) and wins over RUST_LOG, which otherwise replaces the default with env_logger-style directives - never panics: an unusable folder or a failed write leaves standard error as the only sink; a poisoned lock is taken back - runs with LIGHTCRAFT_NO_PREFS (tests, scripts) log to standard error only, so they don't rotate away the user's own logs - a panic hook chained after the engine guard's adds escaped panics to the file (try_lock, so a panic while logging can't hang the app); lightcraft-panics.log in the temp folder is kept The logger is installed first in main and the file is opened after argument parsing (--version, --help and usage errors leave no file). The start-up and control-server messages in main.rs and control_server.rs go through it instead of eprintln!, and a --control or LIGHTCRAFT_CONTROL_PORT value that isn't a port is now reported. Documented in README (Quick start, Logs), --help and docs/whats-new.md.