package log
import "sigs.k8s.io/controller-runtime/pkg/log"
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.
Logr
All logging in controller-runtime is structured, using a set of interfaces defined by a package called logr (https://pkg.go.dev/github.com/go-logr/logr). The sub-package zap provides helpers for setting up logr backed by Zap (go.uber.org/zap).
Index ¶
- Variables
- func FromContext(ctx context.Context, keysAndValues ...interface{}) logr.Logger
- func IntoContext(ctx context.Context, log logr.Logger) context.Context
- func SetLogger(l logr.Logger)
- type KubeAPIWarningLogger
- func NewKubeAPIWarningLogger(opts KubeAPIWarningLoggerOptions) *KubeAPIWarningLogger
- func (l *KubeAPIWarningLogger) HandleWarningHeaderWithContext(ctx context.Context, code int, _ string, message string)
- type KubeAPIWarningLoggerOptions
- type NullLogSink
- func (NullLogSink) Enabled(level int) bool
- func (NullLogSink) Error(_ error, _ string, _ ...interface{})
- func (NullLogSink) Info(_ int, _ string, _ ...interface{})
- func (log NullLogSink) Init(logr.RuntimeInfo)
- func (log NullLogSink) WithName(_ string) logr.LogSink
- func (log NullLogSink) WithValues(_ ...interface{}) logr.LogSink
Variables ¶
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 NullLogSink.
Functions ¶
func FromContext ¶
FromContext returns a logger with predefined values from a context.Context.
func IntoContext ¶
IntoContext takes a context and sets the logger as one of its values. Use FromContext function to retrieve the logger.
func SetLogger ¶
SetLogger sets a concrete logging implementation for all deferred Loggers.
Types ¶
type KubeAPIWarningLogger ¶
type KubeAPIWarningLogger struct {
// contains filtered or unexported fields
}
KubeAPIWarningLogger is a wrapper around a provided logr.Logger that implements the rest.WarningHandlerWithContext interface.
func NewKubeAPIWarningLogger ¶
func NewKubeAPIWarningLogger(opts KubeAPIWarningLoggerOptions) *KubeAPIWarningLogger
NewKubeAPIWarningLogger returns an implementation of rest.WarningHandlerWithContext that logs warnings with code = 299 to the logger passed into HandleWarningHeaderWithContext via the context.
func (*KubeAPIWarningLogger) HandleWarningHeaderWithContext ¶
func (l *KubeAPIWarningLogger) HandleWarningHeaderWithContext(ctx context.Context, code int, _ string, message string)
HandleWarningHeaderWithContext handles logging for responses from API server that are warnings with code being 299 and uses a logr.Logger from context for its logging purposes.
type KubeAPIWarningLoggerOptions ¶
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.WarningHandlerWithContext constructed using NewKubeAPIWarningLogger().
type NullLogSink ¶
type NullLogSink struct{}
NullLogSink is a logr.Logger that does nothing.
func (NullLogSink) Enabled ¶
func (NullLogSink) Enabled(level int) bool
Enabled implements logr.InfoLogger.
func (NullLogSink) Error ¶
func (NullLogSink) Error(_ error, _ string, _ ...interface{})
Error implements logr.Logger.
func (NullLogSink) Info ¶
func (NullLogSink) Info(_ int, _ string, _ ...interface{})
Info implements logr.InfoLogger.
func (NullLogSink) Init ¶
func (log NullLogSink) Init(logr.RuntimeInfo)
Init implements logr.LogSink.
func (NullLogSink) WithName ¶
func (log NullLogSink) WithName(_ string) logr.LogSink
WithName implements logr.Logger.
func (NullLogSink) WithValues ¶
func (log NullLogSink) WithValues(_ ...interface{}) logr.LogSink
WithValues implements logr.Logger.
Source Files ¶
deleg.go log.go null.go warning_handler.go
Directories ¶
Path | Synopsis |
---|---|
pkg/log/zap | Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework. |
- Version
- v0.21.0 (latest)
- Published
- May 20, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 24 minutes ago –
Tools for package owners.