logging

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 5 modules, 48 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logging supplies common constants to ensure consistent use of structured logs.

Index

Constants

View Source
const (
	// ReconcilerKey is used to identify a reconciler.
	ReconcilerKey = "reconciler"

	// QueueKeyKey is used to expose the workqueue key being processed.
	QueueKeyKey = "key"

	// WorkspaceKey is used to specify a workspace when a log is related to an object.
	WorkspaceKey = "workspace"
	// NamespaceKey is used to specify a namespace when a log is related to an object.
	NamespaceKey = "namespace"
	// NameKey is used to specify a name when a log is related to an object.
	NameKey = "name"
	// APIVersionKey is used to specify an API version when a log is related to an object.
	APIVersionKey = "apiVersion"
)

Variables

This section is empty.

Functions

func From

func From(obj Object) []interface{}

From provides the structured logging fields that identify an object, prefixing with the resource name.

func FromPrefix added in v0.8.0

func FromPrefix(prefix string, obj Object) []interface{}

FromPrefix provides the structured logging fields that identify an object, allowing any prefix.

func FromUser added in v0.8.0

func FromUser(u user.Info) []interface{}

FromUser provides the structured logging fields that identify a user, prefixing with 'user'.

func FromUserPrefix added in v0.8.0

func FromUserPrefix(u user.Info, prefix string) []interface{}

FromUserPrefix provides the structured logging fields that identify a user, allowing any prefix.

func IsClientDisconnect added in v0.34.0

func IsClientDisconnect(ctx context.Context, err error) bool

IsClientDisconnect reports whether err means the client went away rather than the server or a backend failing. ctx is the inbound request's context.

A proxy sees this routinely and it is not a fault: a client that cancels a watch, closes a kubectl session or simply goes offline cancels the inbound request, which cancels the outbound one. Logging that at error level turns ordinary client behaviour into a stream of errors that hides real problems, so callers log these at a high verbosity instead, and skip writing a response that nobody is left to read.

func NewReverseProxyErrorLog added in v0.34.0

func NewReverseProxyErrorLog(logger klog.Logger) *log.Logger

NewReverseProxyErrorLog returns a logger for httputil.ReverseProxy.ErrorLog.

Without one, the proxy writes to the standard library logger, which ends up in klog without a level a log pipeline can trust. Most of what it reports there is a watch reaching its timeout mid-stream ("read error during body copy: context deadline exceeded") or a client going away, which happens all the time on a busy proxy and is not a fault. Those are logged at V(4); anything else is logged as an error.

func WithCluster added in v0.8.0

func WithCluster(logger logr.Logger, cluster *request.Cluster) logr.Logger

WithCluster adds requested cluster identifiers to the logger.

func WithObject

func WithObject(logger logr.Logger, obj Object) logr.Logger

WithObject adds object identifiers to the logger.

func WithQueueKey

func WithQueueKey(logger logr.Logger, key string) logr.Logger

WithQueueKey adds the queue key to the logger.

func WithReconciler

func WithReconciler(logger logr.Logger, reconciler string) logr.Logger

WithReconciler adds the reconciler name to the logger.

func WithUser added in v0.8.0

func WithUser(logger logr.Logger, u user.Info) logr.Logger

WithUser adds user identifiers to the logger.

Types

type Object added in v0.8.0

type Object interface {
	metav1.Object
	runtime.Object
}

Directories

Path Synopsis
Package json exists solely to change the date formatting in the JSON log output, which Kubernetes hardcodes to be float-based UNIX timestamps, but which we want as much more useful ISO 8601 date strings.
Package json exists solely to change the date formatting in the JSON log output, which Kubernetes hardcodes to be float-based UNIX timestamps, but which we want as much more useful ISO 8601 date strings.

Jump to

Keyboard shortcuts

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