Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
type Formatter interface {
// Append at the beginning of the log event.
AppendBegin([]byte) []byte
// Append at the end of the log event.
AppendEnd([]byte) []byte
// Append when a group with the given name starts.
AppendOpenGroup(buf []byte, name string) []byte
// Append when a group with the given name ends.
AppendCloseGroup(buf []byte, name string) []byte
// Append an Attr in the context of the given groups.
AppendAttr(buf []byte, a slog.Attr, groups []string) []byte
// Append a separator between Attrs, if one is needed.
AppendSeparatorIfNeeded([]byte) []byte
}
A Formatter formats log output. Each Formatter method takes a []byte buffer, which it should append to and then return.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements a slog.Handler that can produce a variety of output formats. It uses the Formatter interface to produce output.
The main requirement of a format is that preformatted material--groups and attributes that were added using WithGroup and WithAttrs--can be concatenated between the built-in attributes and the remaining attributes.
type Options ¶
type Options struct {
// Level reports the minimum level to log.
// Levels with lower levels are discarded.
// If nil, the Handler uses [slog.LevelInfo].
Level slog.Leveler
// ReplaceAttr rewrites Attrs.
ReplaceAttr func(groups []string, a slog.Attr) slog.Attr
// PCAttrs returns the Attrs to use for source location.
// If nil, no source information is output.
PCAttrs func(pc uintptr) []slog.Attr
}
Options are options for a Handler.
Click to show internal directories.
Click to hide internal directories.