Expand description
Minimal-resource logger for Rust applications.
minimal_logger provides a small, thread-buffered logger with
optional file output, auto flush, and platform-aware log rotation.
§Example
use log::{error, info};
fn main() {
minimal_logger::init().expect("failed to initialise logger");
info!("application started");
error!("shutdown due to error");
minimal_logger::shutdown();
}§Rotation detection
Each thread-local BufWriter<FileWriter> holds an Arc<LogFile> inside
FileWriter. On every log call, load_full() returns the current Arc<LogFile>.
If Arc::ptr_eq fails, a rotation has occurred:
- Flush old
BufWriter→ drains remaining bytes to old file. - Replace with new
BufWriter::with_capacity(capacity, FileWriter(new_arc)). No separate reopen flag check is needed insidewrite_record.
§Flush model
| Trigger | Mechanism |
|---|---|
| Buffer full | BufWriter flushes automatically when internal |
| buffer capacity is reached | |
| Periodic | Background thread sets FLUSH_FLAG; next log call |
calls bw.flush() | |
| Thread exit | BufWriter::drop() calls flush() automatically |
| Explicit | shutdown() / Log::flush() calls bw.flush() |
§Environment variables
| Variable | Default | Description |
|---|---|---|
RUST_LOG | info | Level + per-target filters |
RUST_LOG_FILE | stderr | Absolute path to log file |
RUST_LOG_BUFFER_SIZE | 4096 | Per-thread BufWriter capacity |
RUST_LOG_FLUSH_MS | 1000 | Periodic flush interval (ms) |
RUST_LOG_FORMAT | "{timestamp} [{level:<5}] T[{thread_name}] [{file}:{line}] {args}" | Log message format template (timestamp is fixed 6-digit microseconds) |
Supported format fields: timestamp, level, thread_name, target,
module_path, file, line, args.