Skip to content

v0.1.0

Choose a tag to compare

@h2zi h2zi released this 07 Jul 16:02
v0.1.0
55517b9

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 Compressor interface.
  • 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; Close drains maintenance and is idempotent; ErrClosed after close; Sync satisfies zap's WriteSyncer; Reopen cooperates with external rotators.
  • DST-correct schedules in any WithLocation zone; 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.0

Tested with -race, fuzzed backup-name parsing, 87.7% coverage.