A logr LogSink implementation using go-kit/log.
import (
"os"
"github.com/go-logr/logr"
"github.com/tonglil/gokitlogr"
kitlog "github.com/go-kit/log"
)
func main() {
kl := kitlog.NewJSONLogger(kitlog.NewSyncWriter(os.Stderr))
kl = kitlog.With(kl, "ts", kitlog.DefaultTimestampUTC, "caller", kitlog.Caller(5))
gokitlogr.NameFieldKey = "logger"
gokitlogr.NameSeparator = "/"
var log logr.Logger = gokitlogr.New(&kl)
log = log.WithName("my app")
log = log.WithValues("format", "json")
log.Info("Logr in action!", "the answer", 42)
}
For the most part, concepts in go-kit/log correspond directly with those in logr.
Levels in logr correspond to custom debug levels in go-kit/log. V(0) and V(1) are equivalent to go-kit/log's Info level, while V(2) is equvalent to go-kit/log's Debug level. The Warn level is unused.