logslog

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const LevelFatal = slog.Level(10)

Custom slog level for FATAL (above ERROR which is 8)

View Source
const LevelTrace = slog.Level(-8)

Custom slog level for TRACE (below DEBUG which is -4)

Variables

This section is empty.

Functions

func New

func New(cfg Config) logger.Logger

New creates a new SlogLogger with the given configuration

Types

type Config

type Config struct {
	Level          string    // "trace", "debug", "info", "warn", "error"
	Format         string    // "console" or "json"
	Writer         io.Writer // Output writer, defaults to os.Stdout
	GroupFieldName string    // Field name for groups, defaults to "_group"
}

Config for creating a new SlogLogger

type ConsoleHandler

type ConsoleHandler struct {
	// contains filtered or unexported fields
}

ConsoleHandler is a custom slog handler that outputs colored logs similar to zerolog's console output

func NewConsoleHandler

func NewConsoleHandler(w io.Writer, opts *slog.HandlerOptions, groupFieldName string) *ConsoleHandler

NewConsoleHandler creates a new console handler with colored output

func (*ConsoleHandler) Enabled

func (h *ConsoleHandler) Enabled(_ context.Context, level slog.Level) bool

func (*ConsoleHandler) Handle

func (h *ConsoleHandler) Handle(_ context.Context, r slog.Record) error

func (*ConsoleHandler) WithAttrs

func (h *ConsoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ConsoleHandler) WithGroup

func (h *ConsoleHandler) WithGroup(name string) slog.Handler

type JSONHandler added in v0.2.0

type JSONHandler struct {
	// contains filtered or unexported fields
}

JSONHandler is a wrapper around slog.JSONHandler that properly formats TRACE and FATAL levels

func (*JSONHandler) Enabled added in v0.2.0

func (h *JSONHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*JSONHandler) Handle added in v0.2.0

func (h *JSONHandler) Handle(ctx context.Context, r slog.Record) error

func (*JSONHandler) WithAttrs added in v0.2.0

func (h *JSONHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*JSONHandler) WithGroup added in v0.2.0

func (h *JSONHandler) WithGroup(name string) slog.Handler

type SlogLogger

type SlogLogger struct {
	// contains filtered or unexported fields
}

SlogLogger wraps slog.Logger to implement the logger.Logger interface SlogLogger wraps slog.Logger to implement the logger.Logger interface

func (*SlogLogger) Debug

func (l *SlogLogger) Debug(msg string, keysAndValues ...any)

func (*SlogLogger) Error

func (l *SlogLogger) Error(msg string, keysAndValues ...any)

func (*SlogLogger) Fatal added in v0.2.0

func (l *SlogLogger) Fatal(msg string, keysAndValues ...any)

func (*SlogLogger) Info

func (l *SlogLogger) Info(msg string, keysAndValues ...any)

func (*SlogLogger) Trace

func (l *SlogLogger) Trace(msg string, keysAndValues ...any)

func (*SlogLogger) Warn

func (l *SlogLogger) Warn(msg string, keysAndValues ...any)

func (*SlogLogger) With

func (l *SlogLogger) With(key string, value any) logger.Logger

func (*SlogLogger) WithError

func (l *SlogLogger) WithError(err error) logger.Logger

func (*SlogLogger) WithGroup

func (l *SlogLogger) WithGroup(group string) logger.Logger

Jump to

Keyboard shortcuts

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