zerologr

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT Imports: 3 Imported by: 2

README

zerologr

Lint, test, and build

A clean and simple implementation of the logr interface using a zerolog sink.

Documentation

Overview

Package zerologr is a logr.Logger implementation that uses zerolog for logging. It provides a simple interface to log messages with different verbosity levels and structured logging capabilities. It supports console output and caller information. It is designed to be used as a drop-in replacement for logr.Logger in applications that already use logr for logging.

zerologr does not adapt to zerolog levels, it only logs Info and Error level messages. It does not support Debug or Trace levels, as it is designed to follow the logr interface as closely as possible. It does not make much sense to translate between verbosity and zerolog levels if a package wants to make use of logr for logging.

zerologr will change the global zerolog level to InfoLevel, so that it does not log Debug or Trace level messages by default. This is to ensure that zerologr behaves consistently with the logr interface. It will also set the zerolog MessageFieldName and ErrorFieldName, both and more are possible to override using the Set*FieldName functions of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled returns true if the global logger is enabled for the current verbosity level.

func Error

func Error(err error, msg string, keysAndValues ...any)

Error logs an error message with the global logger.

func Info

func Info(msg string, keysAndValues ...any)

Info logs an info message with the global logger.

func New

func New(opts *Opts) logr.Logger

New creates a new logr.Logger with the specified options.

func Set

func Set(newLogger logr.Logger)

Set replaces the global logger with a new one.

func SetErrorFieldName

func SetErrorFieldName(name string)

SetErrorFieldName sets the error field name for loggers.

func SetMessageFieldName

func SetMessageFieldName(name string)

SetMessageFieldName sets the message field name for loggers.

func SetNameFieldName

func SetNameFieldName(name string)

SetNameFieldName sets the name field name for loggers.

func SetTimestampFieldName

func SetTimestampFieldName(name string)

SetTimestampFieldName sets the timestamp field name for loggers.

func SetVFieldName

func SetVFieldName(name string)

SetVFieldName sets the verbosity field name for loggers.

func V

func V(level int) logr.Logger

V returns the global logger with the specified verbosity level.

func WithCallDepth

func WithCallDepth(depth int) logr.Logger

WithCallDepth returns a new logger with the specified call depth, using the global logger as a base.

func WithName

func WithName(name string) logr.Logger

WithName returns a new logger with the specified name, using the global logger as a base.

func WithValues

func WithValues(keysAndValues ...any) logr.Logger

WithValues returns a new logger with the specified key-value pairs, using the global logger as a base.

Types

type Opts

type Opts struct {
	// Set to true to log to prettily to console. If false, logs are formatted
	// as JSON.
	Console bool
	// Set to true to log the caller file, functiona and line number.
	Caller bool
	// Set the verbosity level. This is used to filter logs at runtime.
	V int
}

Opts is the options for the zerologr logger.

Directories

Path Synopsis
examples
all command
nolint
nolint
stack command
nolint
nolint

Jump to

Keyboard shortcuts

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