Documentation ¶
Overview ¶
Package tslog provides a tinted structured logging implementation.
Index ¶
- func Addr(key string, addr netip.Addr) slog.Attr
- func AddrMarshalText(key string, addr netip.Addr) slog.Attr
- func AddrPort(key string, addrPort netip.AddrPort) slog.Attr
- func AddrPortMarshalText(key string, addrPort netip.AddrPort) slog.Attr
- func AddrPortp(key string, addrPortp *netip.AddrPort) slog.Attr
- func Addrp(key string, addrp *netip.Addr) slog.Attr
- func Err(err error) slog.Attr
- func Int[V ~int | ~int8 | ~int16 | ~int32 | ~int64](key string, value V) slog.Attr
- func Uint[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr](key string, value V) slog.Attr
- type Config
- type Logger
- func (l *Logger) Debug(msg string, attrs ...slog.Attr)
- func (l *Logger) Enabled(level slog.Level) bool
- func (l *Logger) Error(msg string, attrs ...slog.Attr)
- func (l *Logger) Handler() slog.Handler
- func (l *Logger) Info(msg string, attrs ...slog.Attr)
- func (l *Logger) Log(level slog.Level, msg string, attrs ...slog.Attr)
- func (l *Logger) Warn(msg string, attrs ...slog.Attr)
- func (l *Logger) WithAttrs(attrs ...slog.Attr) *Logger
- func (l *Logger) WithGroup(group string) *Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Addr ¶
Addr returns a slog.Attr for a netip.Addr.
If addr is the zero value, the value is the empty string.
func AddrPort ¶
AddrPort returns a slog.Attr for a netip.AddrPort.
If addrPort is the zero value, the value is the empty string.
func AddrPortp ¶
AddrPortp returns a slog.Attr for a *netip.AddrPort.
Use AddrPort if the address is not already on the heap, or the call is guarded by Logger.Enabled.
func Addrp ¶
Addrp returns a slog.Attr for a *netip.Addr.
Use Addr if the address is not already on the heap, or the call is guarded by Logger.Enabled.
Types ¶
type Config ¶
type Config struct { // Level is the minimum level of log messages to write. Level slog.Level `json:"level"` // NoColor disables color in log messages. NoColor bool `json:"no_color"` // NoTime disables timestamps in log messages. NoTime bool `json:"no_time"` // UseTextHandler enables the use of a [*slog.TextHandler] instead of the default tint handler. UseTextHandler bool `json:"use_text_handler"` // UseJSONHandler enables the use of a [*slog.JSONHandler] instead of the default tint handler. UseJSONHandler bool `json:"use_json_handler"` }
Config is a set of options for a *Logger.
func (*Config) NewLoggerWithHandler ¶
NewLoggerWithHandler creates a new *Logger with the given handler.
func (*Config) NewTestLogger ¶
NewTestLogger creates a new *Logger for use in tests.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an opinionated logging implementation that writes structured log messages, tinted with color by default, to its handler.
func (*Logger) Debug ¶
Debug logs the given message at slog.LevelDebug.
func (*Logger) Error ¶
Error logs the given message at slog.LevelError.
func (*Logger) Info ¶
Info logs the given message at slog.LevelInfo.
func (*Logger) Warn ¶
Warn logs the given message at slog.LevelWarn.