Documentation
¶
Index ¶
- Constants
- func NewLevelVar(val *string) (*slog.LevelVar, error)
- func NewReplaceAttr(opts *Options, callback func(groups []string, a slog.Attr) slog.Attr) func(groups []string, a slog.Attr) slog.Attr
- func TranslateToLogLevel(val string) (slog.Level, error)
- type ColorMode
- type FormatMode
- type Logger
- func (l *Logger) AsLog(level slog.Level) *log.Logger
- func (l *Logger) Debugf(format string, v ...any)
- func (l *Logger) Errorf(format string, v ...any)
- func (l *Logger) Fatal(msg string, fields ...any)
- func (l *Logger) Fatalf(format string, v ...any)
- func (l *Logger) Infof(format string, v ...any)
- func (l *Logger) Panic(msg string, fields ...any)
- func (l *Logger) Panicf(format string, v ...any)
- func (l *Logger) Slog() *slog.Logger
- func (l *Logger) Trace(msg string, fields ...any)
- func (l *Logger) Tracef(format string, v ...any)
- func (l *Logger) Warnf(format string, v ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- type LoggerOptionFunc
- type Options
- type SourceMode
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 NewReplaceAttr ¶
Types ¶
type FormatMode ¶
type FormatMode string
type 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 ¶
NewFromSlog converts a slog.Logger to an slogger.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 (*Options) SetFormat ¶
func (o *Options) SetFormat(mode FormatMode) *Options
func (*Options) SetShowTime ¶
func (*Options) SetSourceMode ¶
func (o *Options) SetSourceMode(mode SourceMode) *Options
type SourceMode ¶
type SourceMode string
Click to show internal directories.
Click to hide internal directories.