slogf

package module
v0.0.0-...-d06d6e1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 5 Imported by: 13

README

slogf

Go Reference

Key points

  • logger is a simple func(msg string, attrs ...slog.Attr)
  • minimalistic set of exports
  • slog.TextHandler (aka logfmt) by default
  • no levels by default, errors are passed as just another key=value to logger
    • slogf.Error is exported for convenience

If you want:

Levels

Pass a custom slog.Handler to slogf.New, default one simply ignores them with ReplaceAttr in options

Put levels in logger invocation, or wrap them in separate loggers

Verbosity

Create another slogf.Logf for verbose logs, control verbosity level on your own

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyError = "error"

KeyError sets default key for Error func

Functions

func DefaultHandler

func DefaultHandler(output io.Writer) slog.Handler

DefaultHandler returns a slog.TextHandler that skips level key

func Error

func Error(err error) slog.Attr

Error returns slog.Attr with error string as value and KeyError as key returns empty attr (which is skipped by slog) on nil error

func Value

func Value(key string, valuer slog.LogValuer) slog.Attr

Value is a helper function for slog.LogValuer

Types

type Logf

type Logf func(msg string, attrs ...slog.Attr)

Logf is a func based logger

func New

func New(handler slog.Handler) Logf

New creates a new Logf

func (Logf) With

func (logf Logf) With(attrs ...slog.Attr) Logf

With creates a new Logf with wrapped attrs

Jump to

Keyboard shortcuts

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