klogr

package
v2.130.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 381

README

Minimal Go logging using klog

This package implements the logr interface in terms of Kubernetes' klog. This provides a relatively minimalist API to logging in Go, backed by a well-proven implementation.

Because klogr was implemented before klog itself added supported for structured logging, the default in klogr is to serialize key/value pairs with JSON and log the result as text messages via klog. This does not work well when klog itself forwards output to a structured logger.

Therefore the recommended approach is to let klogr pass all log messages through to klog and deal with structured logging there. Just beware that the output of klog without a structured logger is meant to be human-readable, in contrast to the JSON-based traditional format.

This is a BETA grade implementation.

Documentation

Overview

Package klogr implements github.com/go-logr/logr.Logger in terms of k8s.io/klog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New deprecated

func New() logr.Logger

New returns a logr.Logger which serializes output itself and writes it via klog.

Deprecated: this uses a custom, out-dated output format. Use textlogger.NewLogger instead.

func NewWithOptions deprecated added in v2.5.0

func NewWithOptions(options ...Option) logr.Logger

NewWithOptions returns a logr.Logger which serializes as determined by the WithFormat option and writes via klog. The default is FormatKlog.

Deprecated: FormatSerialize is out-dated. For FormatKlog, use textlogger.NewLogger instead.

Types

type Format added in v2.5.0

type Format string

Format defines how log output is produced.

const (
	// FormatSerialize tells klogr to turn key/value pairs into text itself
	// before invoking klog. Key/value pairs are sorted by key.
	FormatSerialize Format = "Serialize"

	// FormatKlog tells klogr to pass all text messages and key/value pairs
	// directly to klog. Klog itself then serializes in a human-readable
	// format and optionally passes on to a structure logging backend.
	FormatKlog Format = "Klog"
)

type Option added in v2.5.0

type Option func(*klogger)

Option is a functional option that reconfigures the logger created with New.

func WithFormat added in v2.5.0

func WithFormat(format Format) Option

WithFormat selects the output format.

Jump to

Keyboard shortcuts

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