logger

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelOpt  = "level"
	FormatOpt = "format"
)

Variables

View Source
var (
	LevelTrace = slog.LevelDebug - 4
	LevelPanic = slog.LevelError + 8
	LevelFatal = LevelPanic + 2
)
View Source
var DefaultSlogLogger = slog.New(slog.NewTextHandler(
	os.Stderr,
	slogHandlerOpts,
))

DefaultSlogLogger is for convenient usage. Will be overwritten once initializeSlog is called.

View Source
var SlogNopHandler slog.Handler = nopHandler{}

SlogNopHandler discards all logs.

Functions

func Fatal added in v1.5.0

func Fatal(logger FieldLogger, msg string, args ...any)

func GetLogLevel added in v0.8.4

func GetLogLevel(logger FieldLogger) slog.Level

GetLogLevel returns the log level of the current slog.

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the DefaultLogger that was previously setup

func NewLogrFromSlog added in v1.5.0

func NewLogrFromSlog(logger *slog.Logger) logr.Logger

func Panic added in v1.5.0

func Panic(logger FieldLogger, msg string, args ...any)

func ParseLevel added in v1.5.0

func ParseLevel(lvl string) (slog.Level, error)

ParseLevel takes a string level and returns the slog log level constant.

func PopulateLogOpts

func PopulateLogOpts(o LogOptions, level string, format string)

PopulateLogOpts populates the logger options making sure that passed values are valid.

func RegisterExitHandler added in v1.5.0

func RegisterExitHandler(handler func())

func SetDefaultLogLevel added in v1.5.0

func SetDefaultLogLevel()

SetDefaultLogLevel updates the DefaultLogger with the DefaultLogLevel

func SetLogLevel added in v0.10.0

func SetLogLevel(logLevel slog.Level)

SetLogLevel updates the DefaultLogger with a new slog.Level

func SetLogLevelToDebug added in v1.5.0

func SetLogLevelToDebug()

SetLogLevelToDebug updates the DefaultLogger with the logrus.DebugLevel

func SetupLogging

func SetupLogging(o LogOptions, debug bool) error

SetupLogging setup logger options taking into consideration the debug flag.

func Trace added in v1.5.0

func Trace(logger FieldLogger, msg string, args ...any)

Types

type DebugLogger added in v1.2.0

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

func NewDebugLogger added in v1.2.0

func NewDebugLogger(logger *slog.Logger, debugEnabled bool) *DebugLogger

func (*DebugLogger) Debug added in v1.2.0

func (d *DebugLogger) Debug(msg string, args ...interface{})

func (*DebugLogger) DebugLogWithCallers added in v1.2.0

func (d *DebugLogger) DebugLogWithCallers(nCallers int) FieldLogger

func (*DebugLogger) Debugf added in v1.2.0

func (d *DebugLogger) Debugf(format string, args ...interface{})

type FieldLogger added in v1.5.0

type FieldLogger interface {
	Handler() slog.Handler
	With(args ...any) *slog.Logger
	WithGroup(name string) *slog.Logger
	Enabled(ctx context.Context, level slog.Level) bool
	Log(ctx context.Context, level slog.Level, msg string, args ...any)
	LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
	Debug(msg string, args ...any)
	DebugContext(ctx context.Context, msg string, args ...any)
	Info(msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	Warn(msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
	Error(msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
}

type LogFormat

type LogFormat string

type LogOptions

type LogOptions map[string]string

LogOptions maps configuration key-value pairs related to logging.

func (LogOptions) GetLogFormat added in v1.5.0

func (o LogOptions) GetLogFormat() LogFormat

GetLogFormat returns the log format specified in the provided LogOptions. If it is not set in the options or is invalid, it will return the default format.

func (LogOptions) GetLogLevel added in v1.5.0

func (o LogOptions) GetLogLevel() (level slog.Level)

GetLogLevel returns the log level specified in the provided LogOptions. If it is not set in the options, it will return the default level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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