zerolog

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoColorUnderJSONFormat = fmt.Errorf("no_color is only valid when log format is 'console'")

ErrNoColorUnderJSONFormat is returned by Validate when NoColor is enabled while LogFormat is "json"; the option only applies to the console writer.

Functions

func NewLogger

func NewLogger(config *Config) *zerolog.Logger

NewLogger creates a new logger writing to out. The logger will emit a timestamp, the caller's filename, and optionally emit the stacktrace for errors that carry a stack trace.

The Debug and Trace level are samples. It allows up to 100 trace logs per minutes. Additional trace logs will be filtered out. Debug logs are sampled. Every 5th log will be filtered out once the limit of 1000 debug logs per minute is reached.

func NewStdLogger

func NewStdLogger(l *zerolog.Logger) loglib.Logger

func SetGlobalLogger

func SetGlobalLogger(logger *zerolog.Logger)

SetGlobalLogger sets the log output in the stdlib log package and the zerolog global loggers.

Types

type Config

type Config struct {
	// LogLevel selects the minimum log level emitted. Supported values are
	// trace, debug, info, warn, error, fatal, panic, and disabled. An empty
	// string disables level filtering (every event is written).
	LogLevel string
	// LogFormat selects the output encoding. Supported values are "console"
	// (human-readable) and "json" (structured, one JSON object per line).
	// An empty string defaults to "console". Unknown values also fall back
	// to "console"; CLI input is validated up front by Config.Validate.
	LogFormat string
	// NoColor disables ANSI colors in the "console" format. Ignored when
	// LogFormat is "json".
	NoColor bool
}

func (*Config) Validate added in v1.1.0

func (c *Config) Validate() error

Validate returns an error if the Config contains an unsupported value. Empty fields are treated as defaults and accepted.

Jump to

Keyboard shortcuts

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