Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
.circleci/ | H | 20-Jul-2021 | - | 79 | 70 | |
.errcheck_excludes | H A D | 20-Jul-2021 | 35 | 2 | 1 | |
.golangci.yml | H A D | 20-Jul-2021 | 135 | 10 | 8 | |
LICENSE | H A D | 20-Jul-2021 | 11.1 KiB | 202 | 169 | |
README.md | H A D | 20-Jul-2021 | 2.5 KiB | 82 | 64 | |
go.mod | H A D | 20-Jul-2021 | 134 | 9 | 6 | |
go.sum | H A D | 20-Jul-2021 | 1.5 KiB | 18 | 17 | |
klog.go | H A D | 20-Jul-2021 | 4.1 KiB | 166 | 125 | |
klog_test.go | H A D | 20-Jul-2021 | 1.1 KiB | 56 | 47 | |
renovate.json | H A D | 20-Jul-2021 | 41 | 6 | 5 |
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