fastframe-log
Log to stderr and a file for bug reports, keep private data out, and record panics without their payload.
A desktop app launched from a menu has no terminal: the log file is what people attach to bug reports, so it must never hold message contents, phone numbers, keys, tokens, or pairing payloads. This is the setup ZapFast and Spotifast share.
Usage
fastframe_log::Logging::new("zapfast", env!("CARGO_PKG_VERSION"))
// Used when RUST_LOG is unset.
.filter(if verbose { "info,zapfast=debug" } else { "warn,zapfast=info" })
// Created fresh each run, with its folder on a first run, both readable
// by the user alone on Unix; the earlier run's file is kept as
// zapfast.previous.log. Leave it out for demo runs (stderr only).
.file(dirs.log_file())
// Optional: the size the file is kept under (10 MiB by default).
.max_file_size(10 * 1024 * 1024)
// One line per panic, appended.
.panic_log(dirs.panic_log())
// Optional: rewrite the lines of chatty or private targets.
.redact(|record, _message| {
record
.target()
.starts_with("whatsapp_rust")
.then_some("protocol diagnostic (private details omitted)".into())
})
.init()?;
init logs Starting zapfast 0.16.3 on linux (x86_64) once the logger is
up, at info under the app’s name as its target, so a filter such as
warn,zapfast=info keeps it; it also warns (on stderr) if the log file could not be created. The app’s
name and version are passed in; this crate’s version is not the app’s.
Lines look like [2026-09-25T10:00:00Z WARN zapfast::backend] message.
Size limit
No log file grows past 10 MiB (change it with .max_file_size(bytes)).
The writer counts the bytes it writes, so a line costs no more than the
write. When the next line would take zapfast.log past the limit, the file
becomes zapfast.1.log (replacing an older one) and a new zapfast.log
starts, so a run keeps its latest lines: between one and two files’ worth.
A single line longer than the limit is still written whole, into a file of
its own.
At start-up, kept logs of earlier runs that are more than ten times the limit are deleted instead of kept. Only a version without a limit wrote them, and they reached tens of gigabytes when one warning repeated for days.
A copy of the app whose log a later copy moved aside (see below) does not know its new name, so it starts that file over when it fills up instead.
Several copies at once
An app that lets several copies run at once keeps every copy’s log. Each
start moves the earlier run’s file to zapfast.previous.log, unless a copy
that is still running writes that one: then it goes to
zapfast.previous.2.log, or the next number no running copy writes. A file
a running copy writes is never replaced, so a copy never writes on into a
log nobody can open. Logs no running copy writes are replaced as before, so
the numbered files stop at the most copies that ever ran together.
A running copy marks its log with an advisory lock on Unix, which readers never notice; on Windows its open file is the mark. A copy built with an older fastframe sets no lock on Unix, so it is not seen.
Panics
log_panics (called by init when .panic_log is set) replaces the default
panic hook. Each panic appends one line to the panic log (readable by the
user alone on Unix, as the log is) and prints it to stderr:
2026-09-25T10:00:00Z zapfast 0.16.3 on thread "main", panic at src/app.rs:10:5 (payload omitted)
The payload is never written anywhere: an expect or a formatted panic
message can quote whatever the code was handling. The source location is
enough to find the panic.
Apps on tracing
Logging is a log logger, behind the default
logger feature. The panic hook and the redaction helpers use only the
standard library and work with any facade, so an app on tracing takes them
without the logger:
fastframe-log = { git = "https://github.com/crmne/fastframe", rev = "<commit>", default-features = false }
fastframe_log::log_panics(state_dir.join("panic.log"), "solco", env!("CARGO_PKG_VERSION"));
tracing::warn!(error = %fastframe_log::redact::links(&error.to_string()), "download failed");
log_panics replaces the panic hook without chaining the previous one (the
default hook would print the payload). Install it first: a hook set later
that chains std::panic::take_hook(), such as Solco’s session
recorder, then runs before it and keeps working.
There is no tracing subscriber in this crate: only one app logs through
tracing, and it writes no log file. One can follow when a second app
needs it.
Redaction
For single messages, before they are logged:
use fastframe_log::redact;
// Error strings from HTTP clients quote URLs with their tokens.
log::warn!("sticker download failed: {}", redact::links(&error.to_string()));
// Add the shapes an app knows are private.
let cdn = |word: &str| redact::is_link(word) || word.contains("oh=");
log::warn!("{}", redact::words(&error, cdn));
For a whole dependency whose messages can carry private data, pass a
Redactor to .redact and summarise its lines into fixed categories.
Redaction is a net, not the rule: the rule is not to format private values into log lines at levels that ship.