v0.1.0
Initial release of logrotate — a modern rotating-file writer for Go logs, with no third-party dependencies.
Highlights
- Validated functional-options API:
New(path, opts...)surfaces configuration and permission errors at construction, not at the first write; options are immutable afterwards. - Rotation triggers: byte-precision size cap (
WithMaxSize), wall-clock schedules (WithRotateEvery,WithRotateAt) evaluated lazily on write — no timer goroutine, no empty catch-up files, backups stamped with the boundary that ended their period. - Restart-aware: the current rotation period is recovered from the log file's modification time, so a leftover file from a previous period is rotated out at startup.
- Retention:
WithMaxBackups(count),WithMaxAge(duration),WithMaxTotalSize(strict on-disk quota, enforced on post-compression sizes). - Crash-safe background compression: gzip built in via temp-file + fsync + atomic rename; any algorithm plugs in through the two-method
Compressorinterface. - Collision-proof backup names: sequence suffixes instead of silent overwrites; empty files are never rotated into empty backups.
- Observable & clean lifecycle: background errors reach
WithErrorHandler;Closedrains maintenance and is idempotent;ErrClosedafter close;Syncsatisfies zap'sWriteSyncer;Reopencooperates with external rotators. - DST-correct schedules in any
WithLocationzone; UTC by default. - Fast: 0 allocs/op on the write path, within noise of a bare
write(2)syscall.
Install
go get github.com/libtnb/logrotate@v0.1.0Tested with -race, fuzzed backup-name parsing, 87.7% coverage.