log

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CaptureHandler

type CaptureHandler struct {
	// contains filtered or unexported fields
}

CaptureHandler stores records in memory for test assertions.

func NewCaptureHandler

func NewCaptureHandler() *CaptureHandler

func (*CaptureHandler) Close

func (h *CaptureHandler) Close() error

func (*CaptureHandler) Filter

func (h *CaptureHandler) Filter(stream string, level Level) []Record

Filter returns records matching the given stream and minimum level.

func (*CaptureHandler) Handle

func (h *CaptureHandler) Handle(r Record)

func (*CaptureHandler) Records

func (h *CaptureHandler) Records() []Record

Records returns a copy of all captured records.

func (*CaptureHandler) Reset

func (h *CaptureHandler) Reset()

Reset clears all captured records.

type ConsoleHandler

type ConsoleHandler struct {
	// contains filtered or unexported fields
}

ConsoleHandler writes formatted log lines to an io.Writer (typically os.Stderr).

func NewConsoleHandler

func NewConsoleHandler(color bool, minLevel Level) *ConsoleHandler

NewConsoleHandler creates a handler that writes to os.Stderr. Only records at or above minLevel are written.

func NewConsoleHandlerWriter

func NewConsoleHandlerWriter(w io.Writer, color bool, minLevel Level) *ConsoleHandler

NewConsoleHandlerWriter creates a handler that writes to the given writer. Useful for testing.

func (*ConsoleHandler) Close

func (h *ConsoleHandler) Close() error

func (*ConsoleHandler) Handle

func (h *ConsoleHandler) Handle(r Record)

type FileHandler

type FileHandler struct {
	// contains filtered or unexported fields
}

FileHandler writes log records to per-stream files in a directory. Files are created lazily on the first record for each stream. If combined is true, all records are also written to combined.log.

func NewFileHandler

func NewFileHandler(dir string, minLevel Level, combined bool) (*FileHandler, error)

NewFileHandler creates a file handler that writes to {dir}/{stream}.log files. Only records at or above minLevel are written. If combined is true, all records are also appended to combined.log.

func (*FileHandler) Close

func (h *FileHandler) Close() error

func (*FileHandler) Handle

func (h *FileHandler) Handle(r Record)

type Handler

type Handler interface {
	Handle(Record)
	Close() error
}

Handler processes log records.

type Level

type Level int8

Level represents log severity.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelError
)

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel converts a lowercase string ("debug", "info", "error") to a Level.

func (Level) String

func (l Level) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger emits leveled log messages to handlers via a Registry. Create loggers through Registry.NewLogger.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

Debugf logs at DEBUG level.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf logs at ERROR level.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof logs at INFO level.

func (*Logger) With

func (l *Logger) With(prefix string) *Logger

With returns a child Logger with an appended prefix segment.

type Record

type Record struct {
	Time   time.Time
	Level  Level
	Stream string
	Prefix string
	Msg    string
}

Record is a single log entry passed to handlers.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds handlers and per-stream level configuration. It is the central coordinator for the logging system.

func NewRegistry

func NewRegistry(handlers []Handler, levels map[string]Level) *Registry

NewRegistry creates a Registry with the given handlers and per-stream levels. Streams not in the levels map default to LevelInfo.

func (*Registry) Close

func (r *Registry) Close() error

Close closes all handlers and returns the first error encountered.

func (*Registry) NewLogger

func (r *Registry) NewLogger(stream, prefix string) *Logger

NewLogger creates a Logger for the given stream and prefix.

Jump to

Keyboard shortcuts

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