logging

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BySerialDesc

func BySerialDesc(i, j Message) int

BySerialDesc sorts log messages by their serial.

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

type Enricher

type Enricher interface {
	EnrichLogRecord(args ...any) []any
}

Enricher implementations update a log record with further info

type Interface

type Interface interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
	AddEnricher(enricher Enricher)
}
var Discard Interface = &noop{}

type Logger

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

Logger wraps slog, providing further functionality such as emitting log records as pug events, and enriching records with further attributes.

func NewLogger

func NewLogger(opts Options) *Logger

NewLogger constructs Logger, a slog wrapper with additional functionality.

func (Logger) AddEnricher

func (e Logger) AddEnricher(enricher Enricher)

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

func (*Logger) Messages

func (l *Logger) Messages() []Message

Messages provides the log messages received thus far.

func (*Logger) Subscribe

func (l *Logger) Subscribe(ctx context.Context) <-chan resource.Event[Message]

Subscribe to log messages.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

type Message

type Message struct {
	Time       time.Time
	Level      string
	Message    string `json:"msg"`
	Attributes []Attr

	// Serial uniquely identifies the message (within the scope of the logger it
	// was emitted from). The higher the Serial number the newer the message.
	Serial uint
}

Message is the event payload for a log message

type Options

type Options struct {
	// The log level of the logger
	Level string
	// Any additional writers the log handler should write to.
	AdditionalWriters []io.Writer
}

Jump to

Keyboard shortcuts

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