gokitlogr

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

README

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.

Documentation

Overview

Package gokitlogr defines an implementation of the github.com/go-logr/logr interfaces built on top of go-kit/log (https://github.com/go-kit/log).

Usage

A new logr.Logger can be constructed from an existing log.Logger using the New function:

log := gokitlogr.New(someGoKitLogger)

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.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NameFieldKey is the field key for logr.WithName
	NameFieldKey = "logger"
	// NameSeparator separates names for logr.WithName
	NameSeparator = "/"
	// ErrorFieldKey is the field key for logr.Error
	ErrorFieldKey = "error"
	// CallerFieldKey is the field key for call site information
	// When using LogfmtLogger, this should be set to a different key
	// than configured in go-kit/log.Logger to represent the true value
	// of WithCallDepth call sites.
	// When using JSONLogger, this should be set to the same key
	// configured in go-kit/log.Logger to overwrite it with the true value
	// of WithCallDepth call sites.
	CallerFieldKey = "caller"
)

TODO: as options, see: https://github.com/go-logr/zapr/blob/master/zapr.go#L245

Functions

func New

func New(l *kitlog.Logger) logr.Logger

New returns a logr.Logger with logr.LogSink implemented by go-kit/log.

Types

type Underlier

type Underlier interface {
	GetUnderlying() kitlog.Logger
}

Underlier exposes access to the underlying logging implementation. Since callers only have a logr.Logger, they have to know which implementation is in use, so this interface is less of an abstraction and more of way to test type conversion.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL