Documentation
¶
Overview ¶
Package liblog provides a date-organised, size-bounded log directory. Files are named <name>-<YYYY-MM-DD>.log, and a day that outgrows its size bound continues in <name>-<YYYY-MM-DD>.2.log, .3.log, and so on. A Writer is safe for concurrent use, and retention is applied on the write path rather than by a background goroutine.
Index ¶
- Constants
- func FormatSize(n int64) string
- func ParseSize(s string) (int64, error)
- type Config
- type Writer
- func (w *Writer) Close() error
- func (w *Writer) Dir() string
- func (w *Writer) MaxAge() time.Duration
- func (w *Writer) MaxBytes() int64
- func (w *Writer) MaxFiles() int
- func (w *Writer) Path() string
- func (w *Writer) Reconfigure(maxBytes int64, maxFiles int, maxAge time.Duration)
- func (w *Writer) Size() int64
- func (w *Writer) Write(p []byte) (int, error)
Constants ¶
const DefaultMaxAge = 14 * 24 * time.Hour
DefaultMaxAge retires a log by date regardless of how few files exist.
const DefaultMaxBytes int64 = 10 << 20 // 10 MiB
DefaultMaxBytes is a single day-part's default size ceiling.
const DefaultMaxFiles = 14
DefaultMaxFiles is how many log files survive by default, counted across every date and part.
const Unlimited = -1
Unlimited disables a retention bound.
Variables ¶
This section is empty.
Functions ¶
func FormatSize ¶
FormatSize renders a byte count the way ParseSize would accept it back.
Types ¶
type Config ¶
type Config struct {
// Dir is the directory log files live in. Created if absent.
Dir string
// Name is the base name: "serve" yields serve-2026-08-15.log.
Name string
// MaxBytes bounds one part. Non-positive means [DefaultMaxBytes].
MaxBytes int64
// MaxFiles bounds how many files are retained across all dates.
// Non-positive means [DefaultMaxFiles]; use [Unlimited] for no bound.
MaxFiles int
// MaxAge retires files older than this by their date stamp. Zero means
// [DefaultMaxAge]; negative means no age bound.
MaxAge time.Duration
// Now is the clock. Nil means [time.Now].
Now func() time.Time
}
Config describes a log directory. The zero value is not usable.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is an io.WriteCloser over a date-organised log directory.
func Open ¶
Open prepares the log directory and opens today's current part for appending. A restart continues the latest existing part rather than starting a new one.
func (*Writer) Reconfigure ¶
Reconfigure updates the retention bounds of a live log. The directory and name are fixed at Open.