log

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LevelTrace = slog.Level(-8)

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler is a custom slog.Handler that writes out application logs in a human-readable format. We don't really need structured logs for this application; it's just that slog is very easy to work with.

Loosely based on https://github.com/telemachus/humane/blob/0bf66cc42a0f7164f38b525497a74dabd4510ed8/humane.go

func NewHandler

func NewHandler(dest io.Writer, opts *HandlerOptions) *Handler

func (*Handler) Enabled

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

func (*Handler) Handle

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

func (*Handler) WithAttrs

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

func (*Handler) WithGroup

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

type HandlerOptions

type HandlerOptions struct {
	Level     slog.Level
	AddSource bool
}

type Logger

type Logger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

Logger is a wrapper over slog.Logger that writes application logs in its own format.

func New

func New(opts ...Option) (*Logger, error)

func NewDiscardLogger

func NewDiscardLogger() *Logger

func (*Logger) Trace

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

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) *Logger

type Option

type Option func(*Logger) error

func WithDestination

func WithDestination(dest io.Writer) Option

func WithLevel

func WithLevel(level slog.Level) Option

Jump to

Keyboard shortcuts

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