Version: v0.10.3 Latest Latest

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

Go to latest
Published: Nov 10, 2021 License: Apache-2.0 Imports: 4 Imported by: 1,854



Package log contains utilities for fetching a new logger when one is not already available.

The Log Handle

This package contains a root logr.Logger Log. It may be used to get a handle to whatever the root logging implementation is. By default, no implementation exists, and the handle returns "promises" to loggers. When the implementation is set using SetLogger, these "promises" will be converted over to real loggers.


All logging in controller-runtime is structured, using a set of interfaces defined by a package called logr (https://godoc.org/github.com/go-logr/logr). The sub-package zap provides helpers for setting up logr backed by Zap (go.uber.org/zap).



This section is empty.


Log is the base logger used by kubebuilder. It delegates to another logr.Logger. You *must* call SetLogger to get any actual logging. If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get set to a NullLogger.


func FromContext added in v0.6.2

func FromContext(ctx context.Context, keysAndValues ...interface{}) logr.Logger

FromContext returns a logger with predefined values from a context.Context.

func IntoContext added in v0.6.2

func IntoContext(ctx context.Context, log logr.Logger) context.Context

IntoContext takes a context and sets the logger as one of its values. Use FromContext function to retrieve the logger.

func SetLogger

func SetLogger(l logr.Logger)

SetLogger sets a concrete logging implementation for all deferred Loggers.


type DelegatingLogger

type DelegatingLogger struct {
	// contains filtered or unexported fields

DelegatingLogger is a logr.Logger that delegates to another logr.Logger. If the underlying promise is not nil, it registers calls to sub-loggers with the logging factory to be populated later, and returns a new delegating logger. It expects to have *some* logr.Logger set at all times (generally a no-op logger before the promises are fulfilled).

func NewDelegatingLogger

func NewDelegatingLogger(initial logr.Logger) *DelegatingLogger

NewDelegatingLogger constructs a new DelegatingLogger which uses the given logger before it's promise is fulfilled.

func (*DelegatingLogger) Enabled added in v0.8.2

func (l *DelegatingLogger) Enabled() bool

Enabled tests whether this Logger is enabled. For example, commandline flags might be used to set the logging verbosity and disable some info logs.

func (*DelegatingLogger) Error added in v0.8.2

func (l *DelegatingLogger) Error(err error, msg string, keysAndValues ...interface{})

Error logs an error, with the given message and key/value pairs as context. It functions similarly to calling Info with the "error" named value, but may have unique behavior, and should be preferred for logging errors (see the package documentations for more information).

The msg field should be used to add context to any underlying error, while the err field should be used to attach the actual error that triggered this log line, if present.

func (*DelegatingLogger) Fulfill

func (l *DelegatingLogger) Fulfill(actual logr.Logger)

Fulfill switches the logger over to use the actual logger provided, instead of the temporary initial one, if this method has not been previously called.

func (*DelegatingLogger) Info added in v0.8.2

func (l *DelegatingLogger) Info(msg string, keysAndValues ...interface{})

Info logs a non-error message with the given key/value pairs as context.

The msg argument should be used to add some constant description to the log line. The key/value pairs can then be used to add additional variable information. The key/value pairs should alternate string keys and arbitrary values.

func (*DelegatingLogger) V added in v0.8.2

func (l *DelegatingLogger) V(level int) logr.Logger

V returns an Logger value for a specific verbosity level, relative to this Logger. In other words, V values are additive. V higher verbosity level means a log message is less important. It's illegal to pass a log level less than zero.

func (*DelegatingLogger) WithName

func (l *DelegatingLogger) WithName(name string) logr.Logger

WithName provides a new Logger with the name appended.

func (*DelegatingLogger) WithValues

func (l *DelegatingLogger) WithValues(tags ...interface{}) logr.Logger

WithValues provides a new Logger with the tags appended.

type KubeAPIWarningLogger added in v0.9.0

type KubeAPIWarningLogger struct {
	// contains filtered or unexported fields

KubeAPIWarningLogger is a wrapper around a provided logr.Logger that implements the rest.WarningHandler interface.

func NewKubeAPIWarningLogger added in v0.9.0

func NewKubeAPIWarningLogger(l logr.Logger, opts KubeAPIWarningLoggerOptions) *KubeAPIWarningLogger

NewKubeAPIWarningLogger returns an implementation of rest.WarningHandler that logs warnings with code = 299 to the provided logr.Logger.

func (*KubeAPIWarningLogger) HandleWarningHeader added in v0.9.0

func (l *KubeAPIWarningLogger) HandleWarningHeader(code int, agent string, message string)

HandleWarningHeader handles logging for responses from API server that are warnings with code being 299 and uses a logr.Logger for it's logging purposes.

type KubeAPIWarningLoggerOptions added in v0.9.0

type KubeAPIWarningLoggerOptions struct {
	// Deduplicate indicates a given warning message should only be written once.
	// Setting this to true in a long-running process handling many warnings can
	// result in increased memory use.
	Deduplicate bool

KubeAPIWarningLoggerOptions controls the behavior of a rest.WarningHandler constructed using NewKubeAPIWarningLogger().

type NullLogger

type NullLogger struct{}

NullLogger is a logr.Logger that does nothing.

func (NullLogger) Enabled

func (NullLogger) Enabled() bool

Enabled implements logr.InfoLogger.

func (NullLogger) Error

func (NullLogger) Error(_ error, _ string, _ ...interface{})

Error implements logr.Logger.

func (NullLogger) Info

func (NullLogger) Info(_ string, _ ...interface{})

Info implements logr.InfoLogger.

func (NullLogger) V

func (log NullLogger) V(_ int) logr.Logger

V implements logr.Logger.

func (NullLogger) WithName

func (log NullLogger) WithName(_ string) logr.Logger

WithName implements logr.Logger.

func (NullLogger) WithValues

func (log NullLogger) WithValues(_ ...interface{}) logr.Logger

WithValues implements logr.Logger.


Path Synopsis
Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework.
Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework.

Jump to

Keyboard shortcuts

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