slogger

package
v0.0.0-...-713f8c3 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	FormatModeLogfmt FormatMode = "logfmt"
	FormatModeJSON   FormatMode = "json"

	SourceModeNone  SourceMode = "none"
	SourceModeShort SourceMode = "short"
	SourceModeFile  SourceMode = "file"
	SourceModeFull  SourceMode = "full"

	ColorModeDisabled ColorMode = "disabled"
	ColorModeEnabled  ColorMode = "enabled"
	ColorModeAuto     ColorMode = "auto"

	LevelTrace = slog.Level(-8)
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
	LevelFatal = slog.Level(12)
	LevelPanic = slog.Level(255)

	ColorError   = 1
	ColorWarning = 3
	ColorInfo    = 6
	ColorDebug   = 7
)

Variables

This section is empty.

Functions

func NewLevelVar

func NewLevelVar(val *string) (*slog.LevelVar, error)

func NewReplaceAttr

func NewReplaceAttr(opts *Options, callback func(groups []string, a slog.Attr) slog.Attr) func(groups []string, a slog.Attr) slog.Attr

func TranslateToLogLevel

func TranslateToLogLevel(val string) (slog.Level, error)

Types

type ColorMode

type ColorMode string

type FormatMode

type FormatMode string

type Logger

type Logger struct {
	*slog.Logger
}

func New

func New(handler slog.Handler) *Logger

func NewCliLogger

func NewCliLogger(w io.Writer, opts ...LoggerOptionFunc) *Logger

NewCliLogger creates a cli logger with defaults for cli tasks

func NewDaemonLogger

func NewDaemonLogger(w io.Writer, opts ...LoggerOptionFunc) *Logger

NewDaemonLogger creates a logger with defaults for daemons

func NewDiscardLogger

func NewDiscardLogger() *Logger

NewDiscardLogger creates a logger which discards all logs (send logs to /dev/null)

func NewFromSlog

func NewFromSlog(logger *slog.Logger) *Logger

NewFromSlog converts a slog.Logger to an slogger.Logger

func (*Logger) AsLog

func (l *Logger) AsLog(level slog.Level) *log.Logger

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...any)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...any)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...any)

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...any)

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...any)

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...any)

func (*Logger) Slog

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

func (*Logger) Trace

func (l *Logger) Trace(msg string, fields ...any)

func (*Logger) Tracef

func (l *Logger) Tracef(format string, v ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...any)

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

func (*Logger) WithGroup

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

type LoggerOptionFunc

type LoggerOptionFunc func(*Options)

func WithColor

func WithColor(mode ColorMode) LoggerOptionFunc

WithColor sets if logs should be colorful or not

func WithFormat

func WithFormat(mode FormatMode) LoggerOptionFunc

WithFormat sets the mode (logfmt or json)

func WithLevel

func WithLevel(level slog.Level) LoggerOptionFunc

WithLevel sets the log level as slog.Level

func WithLevelText

func WithLevelText(val string) LoggerOptionFunc

WithLevelText sets the log level as string

func WithSourceMode

func WithSourceMode(mode SourceMode) LoggerOptionFunc

WithSourceMode sets the source (file, line) mode

func WithTime

func WithTime(v bool) LoggerOptionFunc

WithTime sets if logs lines should also include the time (not useful for containers)

type Options

type Options struct {
	*slog.HandlerOptions
	SourceMode SourceMode
	Format     FormatMode
	ShowTime   bool
	Color      bool
}

func NewOptions

func NewOptions(opts *slog.HandlerOptions) *Options

func (*Options) SetColorMode

func (o *Options) SetColorMode(mode ColorMode) *Options

func (*Options) SetFormat

func (o *Options) SetFormat(mode FormatMode) *Options

func (*Options) SetLevel

func (o *Options) SetLevel(level slog.Level) *Options

func (*Options) SetShowTime

func (o *Options) SetShowTime(mode bool) *Options

func (*Options) SetSourceMode

func (o *Options) SetSourceMode(mode SourceMode) *Options

type SourceMode

type SourceMode string

Jump to

Keyboard shortcuts

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