logger

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace = slog.LevelDebug - 4
	LevelFatal = slog.LevelError + 4
)

Variables

This section is empty.

Functions

func Init

func Init(o *Opts)

Types

type Opts

type Opts struct {
	Level     string
	Format    string
	AddSource bool
}

type PrettyTextHandler

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

func NewPrettyTextHandler

func NewPrettyTextHandler(out io.Writer, opts *PrettyTextOptions) *PrettyTextHandler

func (*PrettyTextHandler) Enabled

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

func (*PrettyTextHandler) Handle

func (*PrettyTextHandler) WithAttrs

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

func (*PrettyTextHandler) WithGroup

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

type PrettyTextOptions

type PrettyTextOptions struct {
	Level slog.Leveler

	// AddSource adds slog.SourceKey attr, same idea as slog.HandlerOptions.AddSource.
	AddSource bool

	// ReplaceAttr is called to rewrite or drop attributes.
	//
	// To drop an attr, return slog.Attr{}.
	//
	// Built-in attrs passed to ReplaceAttr:
	//   - slog.TimeKey
	//   - slog.LevelKey
	//   - slog.SourceKey, when AddSource is true
	//
	// Message is not passed through ReplaceAttr because this handler prints it
	// as the fixed main log text.
	ReplaceAttr func(groups []string, attr slog.Attr) slog.Attr

	// TimeFormat controls timestamp rendering.
	// Default: "2006-01-02 15:04:05".
	TimeFormat string

	// MessageWidth controls the padded message column.
	// Default: 34.
	MessageWidth int
}

Jump to

Keyboard shortcuts

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