external

package
v0.0.0-...-05acd2d Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(time time.Time, level slog.Level, message string, attrs []slog.Attr) error

Callback is a function that handles nearly untouched slog log records.

type FlattenedAttr

type FlattenedAttr struct {
	slog.Attr
}

FlattenedAttr is a struct that represents a flattened attribute.

This is exactly the same than slog.Attr but:

  • The Key is always a string with the format "group1.group2.group3.key" (if there are 3 encapsulated groups for this key)
  • The Value can't be a group (this is the interest, attributes are flattened with group prefixes in the Key)

type FlattenedAttrsCallback

type FlattenedAttrsCallback func(time time.Time, level slog.Level, message string, attrs []FlattenedAttr) error

FlattenedAttrsCallback is a function that handles slog log records with flattened attributes (no group, prefixed keys with group names).

type Handler

type Handler struct {
	*accumulator.Accumulator
	// contains filtered or unexported fields
}

Handler is an opaque type that implements the slog.Handler interface.

func New

func New(opts *Options) *Handler

New creates a new ExternalHandler.

func (*Handler) Enabled

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

func (*Handler) Handle

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

func (*Handler) WithAttrs

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

func (*Handler) WithGroup

func (eh *Handler) WithGroup(group string) slog.Handler

type Options

type Options struct {
	slog.HandlerOptions
	Callback            Callback                 // If not nil, this callback will be used to handle the log records.
	FlattenedCallback   FlattenedAttrsCallback   // If not nil, this callback (with flattened attributes) will be used to handle the log records.
	StringifiedCallback StringifiedAttrsCallback // If not nil, this callback (with stringified and flattened attributes) will be used to handle the log records.
}

Options is a struct that contains the options for the ExternalHandler.

type StringifiedAttr

type StringifiedAttr struct {
	Key   string
	Value string
}

StringifiedAttr is a struct that represents a stringified slog.Attr attribute.

This is exactly the same than FlattenedAttr but the Value is resolved to a string.

func (StringifiedAttr) String

func (sa StringifiedAttr) String() string

String returns the string representation of the StringifiedAttr as "key=value".

type StringifiedAttrsCallback

type StringifiedAttrsCallback func(time time.Time, level slog.Level, message string, attrs []StringifiedAttr) error

StringifiedAttrsCallback is a function that handles slog log records with stringified and flattened attributes (no group, prefixed keys with group names, values resolved as strings).

Jump to

Keyboard shortcuts

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