Documentation
¶
Overview ¶
Package slogor provides a colorful, allocation-conscious slog.Handler close in spirit to log/slog's own TextHandler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler that writes Records to an io.Writer as a sequence of colorful time, level, source, message and key=value pairs separated by spaces and followed by a newline. A Handler is safe for concurrent use by multiple goroutines, including concurrent calls to Handle, WithAttrs and WithGroup.
func NewHandler ¶
NewHandler creates a Handler that writes to w with the provided Options.
func (*Handler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*Handler) Handle ¶
Handle processes the log record and writes it to the writer with appropriate formatting.
type MapOfLevel ¶ added in v1.5.0
MapOfLevel maps a slog.Level to the exact string used to render it. Levels not present in the map fall back to a "BASE+N"/"BASE-N" form derived from the nearest standard level, mirroring slog.Level.String.
type OptionFn ¶ added in v1.5.0
type OptionFn func(*options)
OptionFn configures a Handler. See NewHandler.
func DisableColor ¶ added in v1.5.0
func DisableColor() OptionFn
DisableColor disables ANSI color output.
func SetLevel ¶ added in v1.5.0
SetLevel sets the minimum log level to handle. By default, level INFO is set.
func SetLevelStr ¶ added in v1.5.0
func SetLevelStr(strLvl MapOfLevel) OptionFn
SetLevelStr sets the handler's level-to-string map. The default map is used if none is specified.
func SetReplaceAttr ¶ added in v1.7.0
func SetReplaceAttr(fn replaceAttrFunc) OptionFn
SetReplaceAttr sets a function to rewrite or drop attributes before they're logged, following the same contract as slog.HandlerOptions.ReplaceAttr. It is called for the built-in time, level, source and msg attributes as well as for user-supplied ones, but never for Group attributes (it is however called for their contents). Returning a zero slog.Attr drops the attribute.
func SetTimeFormat ¶ added in v1.5.0
SetTimeFormat specifies the time format for the log records. By default, nothing is reported.
func ShowSource ¶ added in v1.5.0
func ShowSource() OptionFn
ShowSource indicates whether to display the source of the log records. By default, nothing is reported.
