Documentation ¶
Overview ¶
Package zerologr defines an implementation of the github.com/go-logr/logr interfaces built on top of Zerolog (https://github.com/rs/zerolog).
Usage ¶
A new logr.Logger can be constructed from an existing zerolog.Logger using the New function:
log := zerologr.New(someZeroLogger)
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().
Index ¶
- Variables
- func DefaultRender(keysAndValues []interface{}) []interface{}
- func SetMaxV(level int)
- type LogSink
- func (ls *LogSink) Enabled(level int) bool
- func (ls *LogSink) Error(err error, msg string, keysAndValues ...interface{})
- func (ls *LogSink) GetUnderlying() *zerolog.Logger
- func (ls *LogSink) Info(level int, msg string, keysAndValues ...interface{})
- func (ls *LogSink) Init(ri logr.RuntimeInfo)
- func (ls LogSink) WithCallDepth(depth int) logr.LogSink
- func (ls LogSink) WithName(name string) logr.LogSink
- func (ls LogSink) WithValues(keysAndValues ...interface{}) logr.LogSink
- type Logger
- type Underlier
Constants ¶
This section is empty.
Variables ¶
var ( // NameFieldName is the field key for logr.WithName. NameFieldName = "logger" // NameSeparator separates names for logr.WithName. NameSeparator = "/" // VerbosityFieldName is the field key for logr.Info verbosity. If set to "", // its value is not emitted. VerbosityFieldName = "v" // RenderArgsHook mutates the list of key-value pairs passed directly to // logr.Info and logr.Error. If set to nil, it is disabled. RenderArgsHook = DefaultRender // RenderValuesHook mutates the list of key-value pairs saved via logr.WithValues. // If set to nil, it is disabled. RenderValuesHook = DefaultRender )
Functions ¶
func DefaultRender ¶ added in v1.2.0
func DefaultRender(keysAndValues []interface{}) []interface{}
DefaultRender supports logr.Marshaler and fmt.Stringer.
Types ¶
type LogSink ¶
type LogSink struct {
// contains filtered or unexported fields
}
LogSink implements logr.LogSink and logr.CallDepthLogSink.
func NewLogSink ¶
NewLogSink returns a logr.LogSink implemented by Zerolog.
func (*LogSink) GetUnderlying ¶
GetUnderlying returns the zerolog.Logger underneath this logSink.
func (*LogSink) Info ¶
Info logs a non-error message at specified V-level with the given key/value pairs as context.
func (*LogSink) Init ¶
func (ls *LogSink) Init(ri logr.RuntimeInfo)
Init receives runtime info about the logr library.
func (LogSink) WithCallDepth ¶
WithCallDepth returns a new LogSink that offsets the call stack by adding specified depths.
func (LogSink) WithName ¶
WithName returns a new LogSink with the specified name appended in NameFieldName. Name elements are separated by NameSeparator.
func (LogSink) WithValues ¶
WithValues returns a new LogSink with additional key/value pairs.