File logging for desktop apps, built on tracing.
- No log file is made until something is logged, so with logging off there is none.
- Each run starts a new
<name>.log, and the previous run's log is kept as<name>.log.1. - The level can change while the app runs, such as from an options dialog.
- At the debug and trace levels, only the crates you name are that verbose. Dependencies stay at info, since below that they bury the app's own lines.
- Panics are written to the log, even with
panic = "abort", along with the lines that led up to them. - The
RUST_LOGenvironment variable, when set, replaces the level, so a filter set by hand for debugging isn't overridden by a setting.
use logkeeper::{Level, Logkeeper};
let _guard = Logkeeper::new(config_dir, "fedra").with_crates(["fedra", "fedra-core"]).init(Level::Debug);
tracing::info!("starting");
// Later, when the user picks another level:
logkeeper::set_level(Level::Warn);Keep the guard until the app exits. Dropping it writes out the lines still queued.
Level reads and writes the names off, error, warn, info, debug and trace, ignoring case when reading, so it can be stored in a config file as is. Turning logging off at startup deletes the logs of earlier runs.
MIT