Help us shape the future of Go! Take the 2026 Go Developer Survey

logging

package
v1.8.19 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorLevel = iota
	InfoLevel
	DebugLevel
	TraceLevel

	JSONFormat    Format = "json"
	ConsoleFormat Format = "console"
	DefaultFormat Format = ConsoleFormat

	LogLevelEnvVar  = "LOG_LEVEL"
	LogFormatEnvVar = "LOG_FORMAT"
)

Variables

This section is empty.

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *Logger) context.Context

ContextWithLogger returns a context.Context that has been augmented with the provided *Logger.

Types

type Format

type Format string

func ParseFormat

func ParseFormat(f string) (Format, error)

ParseFormat parses a string representation of a log format and returns the corresponding Format value or an error if it isn't recognized

type Level

type Level uint32

func ParseLevel

func ParseLevel(levelStr string) (Level, error)

ParseLevel parses a string representation of a log level and returns the corresponding Level value.

type Logger

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

Logger is a wrapper around logr.Logger that provides a more ergonomic API. This is heavily inspired by a similar wrapper from https://github.com/kubernetes-sigs/cluster-api-provider-aws

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *Logger

LoggerFromContext extracts a *Logger from the provided context.Context and returns it. If no *Logger is found, a global *Logger is returned.

func NewLogger

func NewLogger(level Level, format Format) (*Logger, error)

NewLogger returns a new *Logger with the provided log level.

func NewLoggerOrDie

func NewLoggerOrDie(level Level, format Format) *Logger

NewLoggerOrDie returns a new *Logger with the provided log level or panics if there is an error configuring the logger

func Wrap

func Wrap(logrLogger logr.Logger) *Logger

Wrap returns a new *Logger that wraps the provided logr.Logger.

func (*Logger) Debug

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

Debug logs a message at the debug level.

func (*Logger) Error

func (l *Logger) Error(err error, msg string, keysAndValues ...any)

Error logs a message at the error level.

func (*Logger) GetLogger

func (l *Logger) GetLogger() logr.Logger

GetLogger returns the underlying logr.Logger for cases where one needs to interact with the logr API directly.

func (*Logger) Info

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

Info logs a message at the info level.

func (*Logger) Trace

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

Trace logs a message at the trace level.

func (*Logger) WithValues

func (l *Logger) WithValues(keysAndValues ...any) *Logger

WithValues adds key-value pairs to a logger's context.

Jump to

Keyboard shortcuts

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