klog

package module
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

klog-gokit CircleCI

This package is a replacement for k8s.io/klog/v2 in projects that use the github.com/go-kit/log module for logging.

The current branch supports neither k8s.io/klog nor github.com/go-kit/kit. Please use the v2.1.0 version instead.

It is heavily inspired by the github.com/kubermatic/glog-gokit package.

Usage

Add this line to your go.mod file:

replace k8s.io/klog/v2 => github.com/simonpasquier/klog-gokit/v3 v3

In your main.go:

// Import the package like it is original klog
import (
    ...
    "github.com/go-kit/log"
    klog "k8s.io/klog/v2"
    ...
)

// Create go-kit logger in your main.go
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
logger = log.With(logger, "ts", log.DefaultTimestampUTC)
logger = log.With(logger, "caller", log.DefaultCaller)
logger = level.NewFilter(logger, level.AllowAll())

// Overriding the default klog with our go-kit klog implementation.
// Thus we need to pass it our go-kit logger object.
klog.SetLogger(logger)

Setting the klog's logger MUST happen at the very beginning of your program (e.g. before using the other klog functions).

Function Levels

klog gokit
Info Debug
InfoDepth Debug
Infof Debug
Infoln Debug
InfoS Debug
InfoSDepth Debug
Warning Warn
WarningDepth Warn
Warningf Warn
Warningln Warn
Error Error
ErrorDepth Error
Errorf Error
Errorln Error
Exit Error
ExitDepth Error
Exitf Error
Exitln Error
Fatal Error
FatalDepth Error
Fatalf Error
Fatalln Error

This table is rather opinionated and build for use with the Kubernetes' Go client.

Disclaimer

This project doesn't aim at covering the complete klog API. That being said, it should work ok for projects that use k8s.io/client-go (like Prometheus for instance).

Limitations

The module implements the klog.Context(context.Context), klog.Background() and klog.TODO() functions but they all return a zero-value Logger which drops all log messages.

License

Apache License 2.0, see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClampLevel

func ClampLevel(l Level)

ClampLevel clamps the leveled logging at the specified value. It must be called prior any call to klog.

func Error

func Error(args ...interface{})

func ErrorDepth

func ErrorDepth(_ int, args ...interface{})

func ErrorS added in v3.3.0

func ErrorS(err error, msg string, keysAndValues ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Exit

func Exit(args ...interface{})

func ExitDepth

func ExitDepth(_ int, args ...interface{})

func Exitf

func Exitf(format string, args ...interface{})

func Exitln

func Exitln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func FatalDepth

func FatalDepth(_ int, args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func InfoDepth

func InfoDepth(_ int, args ...interface{})

func InfoS

func InfoS(msg string, keysAndValues ...interface{})

func InfoSDepth

func InfoSDepth(_ int, msg string, keysAndValues ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func SetLogger

func SetLogger(l log.Logger)

SetLogger redirects klog logging to the given logger. It must be called prior any call to klog.

func Warning

func Warning(args ...interface{})

func WarningDepth

func WarningDepth(_ int, args ...interface{})

func Warningf

func Warningf(format string, args ...interface{})

func Warningln

func Warningln(args ...interface{})

Types

type Level

type Level int32

type Logger added in v3.4.0

type Logger = logr.Logger

func Background added in v3.4.0

func Background() Logger

func FromContext added in v3.4.0

func FromContext(context.Context) Logger

Any function calling klog.FromContext(), klog.Background() or klog.TODO() will get a zero-value logger which drops all the logs.

func TODO added in v3.4.0

func TODO() Logger

type ObjectRef added in v3.1.0

type ObjectRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace,omitempty"`
}

ObjectRef references a kubernetes object

func KRef added in v3.1.0

func KRef(namespace, name string) ObjectRef

KRef returns ObjectRef from name and namespace

type Verbose

type Verbose bool

func V

func V(level Level) Verbose

func (Verbose) Enabled

func (v Verbose) Enabled() bool

func (Verbose) Info

func (v Verbose) Info(args ...interface{})

func (Verbose) InfoS

func (v Verbose) InfoS(msg string, keysAndValues ...interface{})

func (Verbose) InfoSDepth

func (v Verbose) InfoSDepth(_ int, msg string, keysAndValues ...interface{})

func (Verbose) Infof

func (v Verbose) Infof(format string, args ...interface{})

func (Verbose) Infoln

func (v Verbose) Infoln(args ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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