logger

package
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package logger is almost copy/paste from tint Handler but with some modificatoins

Index

Constants

This section is empty.

Variables

View Source
var ShowSQLEvents = false

Functions

func Debug

func Debug(evt any)

func Err

func Err(err error) slog.Attr

Err returns a tinted (colorized) slog.Attr that will be written in red color by the [tint.Handler]. When used with any other slog.Handler, it behaves as

slog.Any("err", err)

func Error

func Error(evt any)

func Info

func Info(evt any)

func Warn

func Warn(evt any)

Types

type Handler

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

Handler implements a slog.Handler.

func NewHandler

func NewHandler(w io.Writer, opts *Options) *Handler

NewHandler creates a slog.Handler that writes tinted logs to Writer w, using the default options. If opts is nil, the default options are used.

func (*Handler) Enabled

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

func (*Handler) Handle

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

func (*Handler) WithAttrs

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

func (*Handler) WithGroup

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

type Options

type Options struct {
	// Enable source code location (Default: false)
	AddSource bool

	// Minimum level to log (Default: slog.LevelInfo)
	Level slog.Leveler

	// ReplaceAttr is called to rewrite each non-group attribute before it is logged.
	// See https://pkg.go.dev/log/slog#HandlerOptions for details.
	ReplaceAttr func(groups []string, attr slog.Attr) slog.Attr
}

Options for a slog.Handler that writes tinted logs. A zero Options consists entirely of default values.

Options can be used as a drop-in replacement for slog.HandlerOptions.

Jump to

Keyboard shortcuts

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