tslog

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tslog provides a tinted structured logging implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addr

func Addr(key string, addr netip.Addr) slog.Attr

Addr returns a slog.Attr for a netip.Addr.

If addr is the zero value, the returned attribute value is the empty string.

func AddrPort

func AddrPort(key string, addrPort netip.AddrPort) slog.Attr

AddrPort returns a slog.Attr for a netip.AddrPort.

If addrPort is the zero value, the returned attribute value is the empty string.

func AddrPortp

func AddrPortp(key string, addrPortp *netip.AddrPort) slog.Attr

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

func Addrp(key string, addrp *netip.Addr) slog.Attr

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.

func ByteString added in v1.9.0

func ByteString(key string, b []byte) slog.Attr

ByteString returns a slog.Attr for a byte slice as a string value without allocating.

func ConnAddr

func ConnAddr(key string, addr conn.Addr) slog.Attr

ConnAddr returns a slog.Attr for a conn.Addr.

func ConnAddrp

func ConnAddrp(key string, addrp *conn.Addr) slog.Attr

ConnAddrp returns a slog.Attr for a *conn.Addr.

Use ConnAddr if the address is not already on the heap, or the call is guarded by Logger.Enabled.

func Err

func Err(err error) slog.Attr

Err is a convenience wrapper for tint.Err.

func Int

func Int[V ~int | ~int8 | ~int16 | ~int32 | ~int64](key string, value V) slog.Attr

Int returns a slog.Attr for a signed integer of any size.

func Prefix added in v1.9.0

func Prefix(key string, prefix netip.Prefix) slog.Attr

Prefix returns a slog.Attr for a netip.Prefix.

If prefix is the zero value, the returned attribute value is the empty string.

func Prefixp added in v1.9.0

func Prefixp(key string, prefixp *netip.Prefix) slog.Attr

Prefixp returns a slog.Attr for a *netip.Prefix.

Use Prefix if the prefix is not already on the heap, or the call is guarded by Logger.Enabled.

func Uint

func Uint[V ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr](key string, value V) slog.Attr

Uint returns a slog.Attr for an unsigned integer of any size.

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) NewHandler added in v1.8.0

func (c Config) NewHandler(w io.Writer) slog.Handler

NewHandler creates a new slog.Handler that writes to w.

func (Config) NewLogger

func (c Config) NewLogger(w io.Writer) *Logger

NewLogger creates a new *Logger that writes to w.

func (Config) NewLoggerWithHandler

func (c Config) NewLoggerWithHandler(handler slog.Handler) *Logger

NewLoggerWithHandler creates a new *Logger with the given handler.

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

func (l *Logger) Debug(msg string, attrs ...slog.Attr)

Debug logs the given message at slog.LevelDebug.

func (*Logger) Enabled

func (l *Logger) Enabled(level slog.Level) bool

Enabled returns whether logging at the given level is enabled.

func (*Logger) Error

func (l *Logger) Error(msg string, attrs ...slog.Attr)

Error logs the given message at slog.LevelError.

func (*Logger) Handler

func (l *Logger) Handler() slog.Handler

Handler returns the logger's handler.

func (*Logger) Info

func (l *Logger) Info(msg string, attrs ...slog.Attr)

Info logs the given message at slog.LevelInfo.

func (*Logger) Log

func (l *Logger) Log(level slog.Level, msg string, attrs ...slog.Attr)

Log logs the given message at the given level.

func (*Logger) Warn

func (l *Logger) Warn(msg string, attrs ...slog.Attr)

Warn logs the given message at slog.LevelWarn.

func (*Logger) WithAttrs

func (l *Logger) WithAttrs(attrs ...slog.Attr) *Logger

WithAttrs returns a new *Logger with the given attributes included in every log message.

func (*Logger) WithGroup

func (l *Logger) WithGroup(group string) *Logger

WithGroup returns a new *Logger that scopes all log messages under the given group.

Jump to

Keyboard shortcuts

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