Documentation
¶
Overview ¶
Package logging provides file-based logging helpers for the CLI.
Index ¶
Constants ¶
const ( DefaultMaxSize = 10 << 20 // 10 MiB DefaultMaxBackups = 5 )
Default rotation limits, applied when a zero or negative value is given.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RotatingWriter ¶
type RotatingWriter struct {
// contains filtered or unexported fields
}
RotatingWriter is an io.Writer that rolls the target log file over once it reaches maxSize bytes. Rotated files are kept as numbered backups (path.1, path.2, ...); backups beyond maxBackups are pruned. Backups are counted on open, so limits stay bounded across restarts.
RotatingWriter is safe for concurrent use; it is installed as a slog sink and slog handlers may be invoked from multiple goroutines at once.
func NewRotatingWriter ¶
func NewRotatingWriter(path string, maxSize int64, maxBackups int) (*RotatingWriter, error)
NewRotatingWriter opens (creating if needed) the log file at path. Parent directories are created as needed. maxSize and maxBackups fall back to the package defaults when zero or negative.
func (*RotatingWriter) Close ¶
func (w *RotatingWriter) Close() error
Close closes the current log file. Close on a closed writer is a no-op.
func (*RotatingWriter) Err ¶
func (w *RotatingWriter) Err() error
Err returns the first write or rotation error encountered, if any.
func (*RotatingWriter) Write ¶
func (w *RotatingWriter) Write(p []byte) (int, error)
Write appends p to the log file, rotating first when the size limit would be crossed. Errors are recorded and returned; callers that ignore them can inspect Err later. When a previous rotation left the writer closed, Write attempts one reopen of the original path before giving up.