logging

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func New(opts Options) (*slog.Logger, io.Closer, error)

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

func Redact(s string) string

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

func SecretAttr(key, value string) slog.Attr

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL