Categorygithub.com/simonpasquier/klog-gokit/v3
modulepackage
3.5.0
Repository: https://github.com/simonpasquier/klog-gokit.git
Documentation: pkg.go.dev

# 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

kloggokit
InfoDebug
InfoDepthDebug
InfofDebug
InfolnDebug
InfoSDebug
InfoSDepthDebug
WarningWarn
WarningDepthWarn
WarningfWarn
WarninglnWarn
ErrorError
ErrorDepthError
ErrorfError
ErrorlnError
ExitError
ExitDepthError
ExitfError
ExitlnError
FatalError
FatalDepthError
FatalfError
FatallnError

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.

# Packages

No description provided by the author

# Functions

No description provided by the author
ClampLevel clamps the leveled logging at the specified value.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Any function calling klog.FromContext(), klog.Background() or klog.TODO() will get a zero-value logger which drops all the logs.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
KRef returns ObjectRef from name and namespace.
LoggerWithName() drops the name argument because klog has no ability to retrieve the existing key and append the argument to it.
SetLogger redirects klog logging to the given logger.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

ObjectRef references a kubernetes object.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author