package logging // import "git.griefed.de/griefed/repoman/internal/logging" Package logging provides repoman's date-based log file rotation. RotatingWriter is an io.WriteCloser that keeps one file per calendar day (UTC) — <dir>/<base>-YYYY-MM-DD.log — rolling to a fresh file on the first write of a new day and pruning files older than a retention window. This is the log4j2 "TimeBasedRollingPolicy / daily rollover" model, implemented in pure Go with no external dependency so repoman stays a single static binary. Both the application log (slog output) and the fail2ban security log write through a RotatingWriter, so they rotate identically. External rotation (logrotate) is therefore no longer required. CONSTANTS const DefaultRetentionDays = 30 DefaultRetentionDays is the fallback retention window (in days) for callers that do not configure one explicitly. TYPES type RotatingWriter struct { // Has unexported fields. } RotatingWriter writes to a per-day file under dir, named "<base>-YYYY-MM-DD.log". It is safe for concurrent use: writes and rolls are serialised under a mutex so lines never interleave or hit a half-rolled file. retentionDays bounds how long old daily files are kept; files whose date is more than retentionDays before the current day are deleted on each roll. A retentionDays of 0 disables pruning (keep everything). func New(dir, base string, retentionDays int) (*RotatingWriter, error) New creates a RotatingWriter for "<dir>/<base>-*.log", creating dir (0700) if missing. The first day file is opened lazily on the first Write, so creating a writer never produces an empty file for a day with no events. func (w *RotatingWriter) Close() error Close closes the currently open day file. Safe to call more than once. func (w *RotatingWriter) Path() string Path returns the path of the day file that is currently open, or "" before the first write. Used by tests and for logging the active log location. func (w *RotatingWriter) Write(p []byte) (int, error) Write appends p to today's file, rolling to a new file (and pruning old ones) first if the calendar day has changed since the last write.