Skip to content

A logr LogSink implementation using go-kit/log

License

Notifications You must be signed in to change notification settings

tonglil/gokitlogr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gokitlogr

Go Reference

Go Report Card

A logr LogSink implementation using go-kit/log.

Usage

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)
}

Implementation Details

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.