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

..03-May-2022-

.circleci/H20-Jul-2021-7970

.errcheck_excludesH A D20-Jul-202135 21

.golangci.ymlH A D20-Jul-2021135 108

LICENSEH A D20-Jul-202111.1 KiB202169

README.mdH A D20-Jul-20212.5 KiB8264

go.modH A D20-Jul-2021134 96

go.sumH A D20-Jul-20211.5 KiB1817

klog.goH A D20-Jul-20214.1 KiB166125

klog_test.goH A D20-Jul-20211.1 KiB5647

renovate.jsonH A D20-Jul-202141 65

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/v2](https://github.com/kubernetes/klog)
4in projects that use the [github.com/go-kit/log](https://pkg.go.dev/github.com/go-kit/log) module for logging.
5
6*The current branch supports neither
7[k8s.io/klog](https://pkg.go.dev/k8s.io/klog) nor
8[github.com/go-kit/kit](https://pkg.go.dev/github.com/go-kit/kit). Please use the `v2.1.0`
9version instead.*
10
11It is heavily inspired by the [`github.com/kubermatic/glog-gokit`](https://github.com/kubermatic/glog-gokit) package.
12
13## Usage
14
15Add this line to your `go.mod` file:
16
17```
18replace k8s.io/klog/v2 => github.com/simonpasquier/klog-gokit/v3 v3
19```
20
21In your `main.go`:
22```go
23// Import the package like it is original klog
24import (
25    ...
26    "github.com/go-kit/log"
27    klog "k8s.io/klog/v2"
28    ...
29)
30
31// Create go-kit logger in your main.go
32logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
33logger = log.With(logger, "ts", log.DefaultTimestampUTC)
34logger = log.With(logger, "caller", log.DefaultCaller)
35logger = level.NewFilter(logger, level.AllowAll())
36
37// Overriding the default klog with our go-kit klog implementation.
38// Thus we need to pass it our go-kit logger object.
39klog.SetLogger(logger)
40```
41
42Setting the klog's logger **MUST** happen at the very beginning of your program
43(e.g. before using the other klog functions).
44
45## Function Levels
46
47|     klog     | gokit |
48| ------------ | ----- |
49| Info         | Debug |
50| InfoDepth    | Debug |
51| Infof        | Debug |
52| Infoln       | Debug |
53| InfoS        | Debug |
54| InfoSDepth   | Debug |
55| Warning      | Warn  |
56| WarningDepth | Warn  |
57| Warningf     | Warn  |
58| Warningln    | Warn  |
59| Error        | Error |
60| ErrorDepth   | Error |
61| Errorf       | Error |
62| Errorln      | Error |
63| Exit         | Error |
64| ExitDepth    | Error |
65| Exitf        | Error |
66| Exitln       | Error |
67| Fatal        | Error |
68| FatalDepth   | Error |
69| Fatalf       | Error |
70| Fatalln      | Error |
71
72This table is rather opinionated and build for use with the Kubernetes' [Go client](https://github.com/kubernetes/client-go).
73
74## Disclaimer
75
76This project doesn't aim at covering the complete `klog` API. That being said, it should work ok for
77projects that use `k8s.io/client-go` (like [Prometheus](https://github.com/prometheus/prometheus) for instance).
78
79## License
80
81Apache License 2.0, see [LICENSE](https://github.com/simonpasquier/klog-gokit/blob/master/LICENSE).
82