file-rotate

A lightweight Rust file writer that rotates and compresses log files by line, byte, or age limits.

Library
Cargo
v0.8.0
41stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
24/100Needs Attention
Development Activity0
Maintenance0
Community24
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
61/100Good
Architecture60
Code Quality62
Innovation55
Learning Curve65

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 FileRotate writer implementing std::io::Write that 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 the SuffixScheme trait for custom naming
  • Optional gzip compression of rotated files via the Compression option
  • 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/ls ordering
  • Compressing rotated logs on the fly to save disk space in resource-constrained deployments
  • Feeding a custom Write sink 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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search