Giter Club home page Giter Club logo

klog-gokit's Introduction

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.

klog-gokit's People

Contributors

dependabot[bot] avatar leviharrison avatar ndrwdn avatar renovate-bot avatar rlankfo avatar simonpasquier avatar tariq1890 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

klog-gokit's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

gomod
go.mod
  • github.com/go-kit/log v0.2.1
  • github.com/go-logr/logr v1.4.1
  • github.com/stretchr/testify v1.8.4
  • go 1.17

  • Check this box to trigger a request for Renovate to run again on this repository

Issues using simonpasquier/klog-gokit 2.1.0 with k8s.io/klog/v2

The README seems indicates that this should be compatible with k8s.io/klog/v2. However, when I attempt to substitute this in go.mod, I see:

vendor/istio.io/pkg/log/config.go:418:32: cannot use NewLogrAdapter(KlogScope) (type logr.Logger) as type "github.com/go-kit/kit/log".Logger in argument to klog.SetLogger:
	logr.Logger does not implement "github.com/go-kit/kit/log".Logger (missing Log method)

Removing the require override from go.mod causes the builder failure to go away.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.