log

package
v1.4.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in production.
	DebugLevel = Level(zapcore.DebugLevel)
	// InfoLevel is the default logging priority.
	InfoLevel = Level(zapcore.InfoLevel)
	// WarnLevel logs are more important than Info, but don't need individual human review.
	WarnLevel = Level(zapcore.WarnLevel)
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = Level(zapcore.ErrorLevel)
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel = Level(zapcore.DPanicLevel)
	// PanicLevel logs a message, then panics.
	PanicLevel = Level(zapcore.PanicLevel)
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = Level(zapcore.FatalLevel)
)

Variables

View Source
var (
	// Log is the base logger
	Log  logr.Logger = logr.New(ctrllog.NullLogSink{})
	Sync io.Writer
)

Functions

func NewLogger

func NewLogger(opts ...Opts) logr.Logger

NewLogger creates new Logger with context filtering for trace extraction

func SetLevel

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

SetLevel sets Options.LogLevel, which configures the the minimum enabled logging level e.g Debug, Info.

func SetLogger

func SetLogger(logger logr.Logger)

SetLogger sets a concrete logging implementation for all deferred Loggers. Being top level application and not a library or dependency, let's delegation logger used by any dependency

func SetMode

func SetMode(mode Mode) func(o *Options)

SetMode sets Options.LogMode, which configures to use (or not use) development mode

func SetSync added in v1.3.0

func SetSync(sync io.Writer)

SetSync sets the zapcore.WriterSyncer used to write the logs.

func SetupOTelLogging added in v1.4.0

func SetupOTelLogging(ctx context.Context, config *otel.Config, zapLevel Level, zapMode Mode, zapWriter io.Writer) (logr.Logger, error)

SetupOTelLogging sets up OpenTelemetry logging with the given configuration. It creates a Zap logger with a Tee core that sends logs to both: - Console output (formatted via Zap encoder) - OTel LoggerProvider (for OTLP export to remote collectors) using official otelzap bridge Returns a logr.Logger that wraps the Zap logger Returns an error if no logs endpoint is configured.

func ShutdownOTelLogging added in v1.4.0

func ShutdownOTelLogging(ctx context.Context) error

ShutdownOTelLogging gracefully shuts down the OpenTelemetry logger provider

Types

type Level

type Level zapcore.Level

Level configures the verbosity of the logging.

func ToLevel

func ToLevel(level string) Level

ToLevel converts a string to a log level.

type Mode

type Mode int8

Mode defines the log output mode.

const (
	// ModeProd is the log mode for production.
	ModeProd Mode = iota
	// ModeDev is for more human-readable outputs, extra stack traces
	// and logging info. (aka Zap's "development config".)
	// https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log/zap#UseDevMode
	ModeDev
)

func ToMode

func ToMode(mode string) Mode

ToMode converts a string to a log mode. Use either 'production' for `LogModeProd` or 'development' for `LogModeDev`.

type Options

type Options struct {
	// LogLevel configures the verbosity of the logging.
	LogLevel Level
	// LogMode defines the log output mode.
	LogMode Mode
	// DestWriter controls the destination of the log output.  Defaults to
	// os.Stderr.
	DestWriter io.Writer
}

Options contains all possible settings.

type Opts

type Opts func(*Options)

Opts allows to manipulate Options.

func WriteTo

func WriteTo(out io.Writer) Opts

WriteTo configures the logger to write to the given io.Writer, instead of standard error. See Options.DestWriter.

Jump to

Keyboard shortcuts

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