• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.circleci/H06-Oct-2020-

v2/H20-Jul-2021-

.errcheck_excludesH A D06-Oct-202039

.golangci.ymlH A D06-Oct-2020135

LICENSEH A D06-Oct-202011.1 KiB

README.mdH A D06-Oct-20202.5 KiB

go.modH A D06-Oct-2020132

go.sumH A D06-Oct-202035.1 KiB

klog.goH A D06-Oct-20203.5 KiB

klog_test.goH A D06-Oct-20201.1 KiB

renovate.jsonH A D06-Oct-202041

README.md

1# klog-gokit [![CircleCI](https://circleci.com/gh/simonpasquier/klog-gokit.svg?style=svg)](https://circleci.com/gh/simonpasquier/klog-gokit)
2
3This package is a replacement for [k8s.io/klog](https://github.com/kubernetes/klog)
4in projects that use the [go-kit logger](https://godoc.org/github.com/go-kit/kit/log).
5
6It also supports [k8s.io/klog/v2](https://pkg.go.dev/k8s.io/klog/v2).
7
8It is heavily inspired by the [`github.com/kubermatic/glog-gokit`](https://github.com/kubermatic/glog-gokit) package.
9
10## Usage
11
12Override the official klog package with this one.
13This simply replaces the code in `vendor/k8s.io/klog` with the code of this package.
14
15**With dep**
16
17In your `Gopkg.toml`:
18```toml
19[[override]]
20  name = "k8s.io/klog"
21  source = "github.com/simonpasquier/klog-gokit"
22```
23
24**With Go modules**
25
26Add this line to your `go.mod` file:
27
28```
29replace k8s.io/klog => github.com/simonpasquier/klog-gokit master
30```
31
32In your `main.go`:
33```go
34// Import the package like it is original klog
35import "k8s.io/klog"
36
37
38// Create go-kit logger in your main.go
39logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
40logger = log.With(logger, "ts", log.DefaultTimestampUTC)
41logger = log.With(logger, "caller", log.DefaultCaller)
42logger = level.NewFilter(logger, level.AllowAll())
43
44// Overriding the default klog with our go-kit klog implementation.
45// Thus we need to pass it our go-kit logger object.
46klog.SetLogger(logger)
47```
48
49Setting the logger to the klog package **MUST** happen before using klog in any package.
50
51## Function Levels
52
53|     klog     | gokit |
54| ------------ | ----- |
55| Info         | Debug |
56| InfoDepth    | Debug |
57| Infof        | Debug |
58| Infoln       | Debug |
59| Warning      | Warn  |
60| WarningDepth | Warn  |
61| Warningf     | Warn  |
62| Warningln    | Warn  |
63| Error        | Error |
64| ErrorDepth   | Error |
65| Errorf       | Error |
66| Errorln      | Error |
67| Exit         | Error |
68| ExitDepth    | Error |
69| Exitf        | Error |
70| Exitln       | Error |
71| Fatal        | Error |
72| FatalDepth   | Error |
73| Fatalf       | Error |
74| Fatalln      | Error |
75
76This table is rather opinionated and build for use with the Kubernetes' [Go client](https://github.com/kubernetes/client-go).
77
78## Disclaimer
79
80This project doesn't aim at covering the complete `klog` API. That being said, it should work ok for
81projects that use `k8s.io/client-go` (like [Prometheus](https://github.com/prometheus/prometheus) for instance).
82
83## License
84
85Apache License 2.0, see [LICENSE](https://github.com/simonpasquier/klog-gokit/blob/master/LICENSE).
86