Documentation
¶
Index ¶
- Constants
- Variables
- func Fatal(logger FieldLogger, msg string, args ...any)
- func GetLogLevel(logger FieldLogger) slog.Level
- func GetLogger() *slog.Logger
- func NewLogrFromSlog(logger *slog.Logger) logr.Logger
- func Panic(logger FieldLogger, msg string, args ...any)
- func ParseLevel(lvl string) (slog.Level, error)
- func PopulateLogOpts(o LogOptions, level string, format string)
- func RegisterExitHandler(handler func())
- func SetDefaultLogLevel()
- func SetLogLevel(logLevel slog.Level)
- func SetLogLevelToDebug()
- func SetupLogging(o LogOptions, debug bool) error
- func Trace(logger FieldLogger, msg string, args ...any)
- type DebugLogger
- type FieldLogger
- type LogFormat
- type LogOptions
Constants ¶
const ( LevelOpt = "level" FormatOpt = "format" )
Variables ¶
var ( LevelTrace = slog.LevelDebug - 4 LevelPanic = slog.LevelError + 8 LevelFatal = LevelPanic + 2 )
var DefaultSlogLogger = slog.New(slog.NewTextHandler( os.Stderr, slogHandlerOpts, ))
DefaultSlogLogger is for convenient usage. Will be overwritten once initializeSlog is called.
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 Panic ¶ added in v1.5.0
func Panic(logger FieldLogger, msg string, args ...any)
func ParseLevel ¶ added in v1.5.0
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
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 LogOptions ¶
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.