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 ¶
- func Enabled() bool
- func Error(err error, msg string, keysAndValues ...any)
- func Info(msg string, keysAndValues ...any)
- func New(opts *Opts) logr.Logger
- func Set(newLogger logr.Logger)
- func SetErrorFieldName(name string)
- func SetMessageFieldName(name string)
- func SetNameFieldName(name string)
- func SetTimestampFieldName(name string)
- func SetVFieldName(name string)
- func V(level int) logr.Logger
- func WithCallDepth(depth int) logr.Logger
- func WithName(name string) logr.Logger
- func WithValues(keysAndValues ...any) logr.Logger
- type Opts
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 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 WithCallDepth ¶
WithCallDepth returns a new logger with the specified call depth, using the global logger as a base.
func WithName ¶
WithName returns a new logger with the specified name, using the global logger as a base.
func WithValues ¶
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.