Documentation
¶
Overview ¶
Original implementation: https://github.com/dpotapov/slogpfx
Original implementation: https://github.com/lmittmann/tint
Index ¶
- func ColorizePrefix(f func(prefixes []slog.Value) string) func(prefixes []slog.Value) string
- func DefaultPrefixFormatter(prefixes []slog.Value) string
- func Err(err error) slog.Attr
- func Level(level string) slog.Level
- func NewAwesomeJsonLogger(options *Options) *slog.Logger
- func NewAwesomeLogger(options *Options) *slog.Logger
- func NewAwesomeTextLogger(options *Options) *slog.Logger
- func NewTintedHandler(w io.Writer, opts *Options) slog.Handler
- type Handler
- type HandlerOptions
- type LogFormat
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorizePrefix ¶
ColorizePrefix wraps a prefix formatter function to colorize its output with cyan ANSI codes.
func DefaultPrefixFormatter ¶
DefaultPrefixFormatter constructs a prefix string by joining all detected prefix values using ":". A " > " suffix is added at the end of the prefix string.
func Err ¶
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 NewAwesomeJsonLogger ¶
func NewAwesomeLogger ¶
func NewAwesomeTextLogger ¶
func NewTintedHandler ¶
NewTintedHandler creates a slog.Handler that writes tinted logs to Writer w, using the default options. If opts is nil, the default options are used.
Types ¶
type Handler ¶
type Handler struct { Next slog.Handler // The next log tintedHandler in the chain. // contains filtered or unexported fields }
Handler is a custom slog tintedHandler that wraps another slog.Handler to prepend a prefix to the log messages. The prefix is sourced from the log record's attributes using the keys specified in PrefixKeys.
func NewPrefixedHandler ¶
func NewPrefixedHandler(next slog.Handler, opts *HandlerOptions) *Handler
NewTintedHandler creates a new prefix logging tintedHandler. The new tintedHandler will prepend a prefix sourced from the log record's attributes to each log message before passing the record to the next tintedHandler.
type HandlerOptions ¶
type HandlerOptions struct { PrefixKeys []string // A list of keys used to fetch prefix values from the log record. // PrefixFormatter is a function to format the prefix of the log record. // If it's not set, the DefaultPrefixFormatter with ColorizePrefix wrapper is used. PrefixFormatter func(prefixes []slog.Value) string }
type Options ¶
type Options struct { Format LogFormat // 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://pkgo.dev/log/slog#HandlerOptions for details. ReplaceAttr func(groups []string, attr slog.Attr) slog.Attr PrefixKeys []string // Time format (Default: time.StampMilli) TimeFormat string // Disable color (Default: false) NoColor bool }
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.