file-rotate
A lightweight Rust file writer that rotates and compresses log files by line, byte, or age limits.
Repository Health
Technical Analysis
file-rotate is a small Rust crate that implements std::io::Write for a file handle which automatically rotates itself once a configured content limit is reached. It supports rotating by number of lines, total bytes, or a custom timestamp suffix, and can optionally gzip old files as they roll over so long-running processes don’t fill a disk with uncompressed logs.
Because it’s just a Write implementation, it plugs into any logging middleware (tracing, log, slog, or a raw writer) without requiring a specific logging framework. It also exposes helpers to enumerate the current set of rotated log files, and supports age-based deletion so old logs are pruned automatically after a configurable retention window.
What You Get
- A
FileRotatewriter implementingstd::io::Writethat drops into any logging pipeline - Rotation triggered by line count, byte size (
ContentLimit), or elapsed time via timestamp suffixes - Pluggable suffix schemes (
AppendCount,AppendTimestamp) via theSuffixSchemetrait for custom naming - Optional gzip compression of rotated files via the
Compressionoption - Age-based deletion of old log files so retention is bounded automatically
- A
log_paths()helper to list all current rotated files for a base path
Common Use Cases
- Bounding disk usage for a long-running Rust service’s log files without an external logrotate daemon
- Rotating application logs by day using timestamp suffixes for easy chronological
cat/lsordering - Compressing rotated logs on the fly to save disk space in resource-constrained deployments
- Feeding a custom
Writesink into higher-level logging crates that expect a plain writer target
Under The Hood
Architecture The crate centers on a FileRotate struct that wraps a base file path and implements std::io::Write; each write checks the configured ContentLimit (lines or bytes) and, once exceeded, closes the current file, renames it according to a SuffixScheme (count-based or timestamp-based), optionally gzips it via compression.rs, prunes files beyond the retention limit, and opens a fresh file at the base path. Tech Stack It’s a small, dependency-light Rust crate (edition 2018) built on chrono for timestamp suffix formatting and flate2 for gzip compression, with quickcheck, tempfile, and filetime used only in dev-dependencies for property-based and filesystem-timing tests. Code Quality The implementation is concentrated in a ~780-line lib.rs plus a ~440-line suffix.rs for naming schemes and a dedicated 628-line tests.rs covering rotation-by-lines, rotation-by-bytes, timestamp ordering, and compression behavior with both unit and quickcheck property tests, though the project has seen little maintenance activity recently. API Design The public API is a single FileRotate::new(path, suffix_scheme, content_limit, compression, retention) constructor plus a plain Write implementation, so it composes directly with any logging crate; the module-level docs on lib.rs double as runnable doctests covering the common configurations.
Used by 2 apps in this directory
Anarlog
Note Taking · AI Assistants · Productivity
Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.