Documentation
¶
Overview ¶
Package logging builds the server logger: JSON lines to a size-rotated file under the data directory plus human-readable text on the console, with helpers that keep secrets out of both.
Index ¶
Constants ¶
const ( // FileName is the live log file inside Options.Dir. FileName = "bubbles.log" // DefaultMaxSize is the size at which the log file rotates. DefaultMaxSize int64 = 10 << 20 // DefaultMaxFiles is the number of log files kept, live file included. DefaultMaxFiles = 5 // Redacted replaces any value that must never reach a log. Redacted = "[redacted]" )
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a logger that writes JSON to <Dir>/bubbles.log (mode 0600, rotated) and, when Console is set, text to Console. Close the returned closer on shutdown to flush and release the log file.
func Redact ¶
Redact returns a stand-in for a secret. It never reveals any part of s: an empty s stays empty (nothing to hide) and anything else becomes Redacted.
func SecretAttr ¶
SecretAttr is a slog attribute for a secret value; only the redacted form is logged.
Types ¶
type Options ¶
type Options struct {
Dir string // directory holding bubbles.log (required)
Console io.Writer // text output; nil disables console logging
Level slog.Leveler // minimum level; nil means info
MaxSize int64 // rotation size in bytes; 0 means DefaultMaxSize
MaxFiles int // files kept, live included; 0 means DefaultMaxFiles
}
Options configures New. Zero values select the defaults.
type RotatingWriter ¶
type RotatingWriter struct {
// contains filtered or unexported fields
}
RotatingWriter appends to a log file and rotates it once a write would push it past maxSize. The live file is path; older generations are path.1 (newest) to path.<maxFiles-1> (oldest), so at most maxFiles files exist. It is safe for concurrent use.
func NewRotatingWriter ¶
func NewRotatingWriter(path string, maxSize int64, maxFiles int) (*RotatingWriter, error)
NewRotatingWriter opens (creating with mode 0600 if needed) the log file at path. maxSize is in bytes; maxFiles counts the live file plus its backups and must be at least 1 (1 means the file is truncated on rotation).
func (*RotatingWriter) Close ¶
func (w *RotatingWriter) Close() error
Close closes the live file. Later writes fail with os.ErrClosed.
func (*RotatingWriter) Reopen ¶
func (w *RotatingWriter) Reopen(clear func() error) error
Reopen closes the live file, runs clear (which may delete every log file: nothing holds them open meanwhile, as Windows requires) and opens a fresh live file. Writes wait while it runs. Factory reset uses it to wipe the logs of a running server.
func (*RotatingWriter) Write ¶
func (w *RotatingWriter) Write(p []byte) (int, error)
Write implements io.Writer. A failed rotation is not fatal: the entry is appended to the current file so log lines are not lost. If the live file could not be reopened, Write retries the open first, so one failed rotation does not make the writer fail forever.