Categorygithub.com/go-logr/zerologr
modulepackage
1.2.3
Repository: https://github.com/go-logr/zerologr.git
Documentation: pkg.go.dev

# README

Zerologr

Go Reference test Go Report Card

A logr LogSink implementation using Zerolog.

Usage

import (
    "os"

    "github.com/go-logr/logr"
    "github.com/go-logr/zerologr"
    "github.com/rs/zerolog"
)

func main() {
    zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs

    zerologr.NameFieldName = "logger"
    zerologr.NameSeparator = "/"
    zerologr.SetMaxV(1)

    zl := zerolog.New(os.Stderr)
    zl = zl.With().Caller().Timestamp().Logger()
    var log logr.Logger = zerologr.New(&zl)

    log.Info("Logr in action!", "the answer", 42)
}

Implementation Details

For the most part, concepts in Zerolog correspond directly with those in logr.

V-levels in logr correspond to levels in Zerolog as zerologLevel = 1 - logrV. logr.V(0) is equivalent to zerolog.InfoLevel or 1; logr.V(1) is equivalent to zerolog.DebugLevel or 0 (default global level in Zerolog); logr.V(2) is equivalent to zerolog.TraceLevel or -1. Higher than 2 V-level is possible but misses some features in Zerolog, e.g. Hooks and Sampling. V-level value is a number and is only logged on Info(), not Error().

# Packages

No description provided by the author

# Functions

DefaultRender supports logr.Marshaler and fmt.Stringer.
New returns a logr.Logger with logr.LogSink implemented by Zerolog.
NewLogSink returns a logr.LogSink implemented by Zerolog.
SetMaxV updates Zerolog's global level.

# Variables

NameFieldName is the field key for logr.WithName.
NameSeparator separates names for logr.WithName.
RenderArgsHook mutates the list of key-value pairs passed directly to logr.Info and logr.Error.
RenderValuesHook mutates the list of key-value pairs saved via logr.WithValues.
VerbosityFieldName is the field key for logr.Info verbosity.

# Structs

LogSink implements logr.LogSink and logr.CallDepthLogSink.

# Interfaces

Underlier exposes access to the underlying logging implementation.

# Type aliases

Logger is type alias of logr.Logger.