tracelog

package
v1.122.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MPL-2.0 Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.115.0

type Config struct {
	// Level is the minimum log level that will be emitted. Defaults to slog.LevelInfo if not set.
	Level slog.Leveler
	// LevelNames is an optional map of slog.Level to string that will be used to format the log level. If not set, the
	// default slog level names will be used.
	LevelNames map[slog.Level]string
	// Sink is the io.Writer that will receive the formatted log output. Defaults to os.Stderr if not set.
	Sink io.Writer
	// BufferDepth greater than 0 will enable asynchronous delivery of log messages to the sink. When enabled, if there
	// is no room remaining in the buffer, the message will be discarded rather than waiting for room to become
	// available. Defaults to 0 for synchronous delivery.
	BufferDepth int
}

Config is used to configure a Handler.

func (*Config) Normalize added in v1.115.0

func (c *Config) Normalize()

Normalize ensures that the Config is valid.

type Handler

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

Handler provides a formatted text output that may include a stack trace on separate lines. The stack trace is formatted such that most IDEs will auto-generate links for it within their consoles. Note that this slog.Handler is not optimized for performance, as I expect those that need to run this is environments where that matters will use one of the implementations provided by slog itself.

func New

func New(cfg *Config) *Handler

New creates a new Handler. May pass nil for cfg to use the defaults.

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements slog.Handler.

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle implements slog.Handler.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

Jump to

Keyboard shortcuts

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