logging

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLevel = "info"

Variables

This section is empty.

Functions

func BySerialDesc

func BySerialDesc(i, j Message) int

BySerialDesc sorts log messages by their serial.

func ValidLevels added in v0.4.0

func ValidLevels() []string

ValidLevels returns valid strings for choosing a log level. Returns the default log level first.

Types

type ArgsUpdater added in v0.5.2

type ArgsUpdater interface {
	UpdateArgs(args ...any) []any
}

ArgsUpdater updates a log message's arguments.

type Attr

type Attr struct {
	Key   string
	Value string

	// An attribute is a pug resource, but only insofar as it makes it easier to
	// handle consistently alongside all other resources (modules, workspaces,
	// etc) in the TUI.
	resource.ID
}

type Getter added in v0.5.2

type Getter[T any] interface {
	Get(resource.ID) (T, error)
}

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)
	AddArgsUpdater(enricher ArgsUpdater)
}
var Discard Interface = &noop{}

type Logger

type Logger struct {
	*pubsub.Broker[Message]
	// 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) AddArgsUpdater added in v0.5.2

func (e Logger) AddArgsUpdater(updater ArgsUpdater)

func (*Logger) Debug

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

func (*Logger) Error

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

func (*Logger) Get added in v0.1.9

func (l *Logger) Get(id resource.ID) (Message, error)

Get retrieves a log message by ID.

func (*Logger) Info

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

func (*Logger) List added in v0.1.9

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

List lists the log messages received thus far.

func (*Logger) Warn

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

type Message

type Message struct {
	// A message is a pug resource, but only insofar as it makes it easier to
	// handle consistently alongside all other resources (modules, workspaces,
	// etc) in the TUI.
	resource.ID

	Time       time.Time
	Level      string
	Message    string `json:"msg"`
	Attributes []Attr
}

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
}

type ReferenceUpdater added in v0.5.2

type ReferenceUpdater[T any] struct {
	Getter[T]

	Name  string
	Field string
}

ReferenceUpdater checks log arguments for references to T via its ID, either directly or via a struct field, and updates or adds T to the log arguments accordingly.

func (*ReferenceUpdater[T]) UpdateArgs added in v0.5.2

func (e *ReferenceUpdater[T]) UpdateArgs(args ...any) []any

Jump to

Keyboard shortcuts

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