zerolog

package
v0.0.0-...-26def9a Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DebugLevel defines debug log level.
	DebugLevel = Level(zerolog.DebugLevel)
	// InfoLevel defines info log level.
	InfoLevel = Level(zerolog.InfoLevel)
	// WarnLevel defines warn log level.
	WarnLevel = Level(zerolog.WarnLevel)
	// ErrorLevel defines error log level.
	ErrorLevel = Level(zerolog.ErrorLevel)
	// FatalLevel defines fatal log level.
	FatalLevel = Level(zerolog.FatalLevel)
	// PanicLevel defines panic log level.
	PanicLevel = Level(zerolog.PanicLevel)
	// NoLevel defines an absent log level.
	NoLevel = Level(zerolog.NoLevel)
	// Disabled disables the logger.
	Disabled = Level(zerolog.Disabled)

	// TraceLevel defines trace log level.
	TraceLevel = Level(zerolog.TraceLevel)
)

Variables

View Source
var StdLogger = New(os.Stderr)

Logger is the global logger.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicln

func Panicln(args ...interface{})

func Print

func Print(args ...interface{})

func Printf

func Printf(format string, args ...interface{})

func Println

func Println(args ...interface{})

func SetGlobalLevel

func SetGlobalLevel(l Level)

func ToStd

func ToStd(logger *Logger) *stdLogger

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warnln

func Warnln(args ...interface{})

Types

type Context

type Context zerolog.Context

func (Context) AnErr

func (c Context) AnErr(key string, err error) Context

AnErr adds the field key with serialized err to the logger context.

func (Context) Array

func (c Context) Array(key string, arr zerolog.LogArrayMarshaler) Context

Array adds the field key with an array to the event context. Use zerolog.Arr() to create the array or pass a type that implement the LogArrayMarshaler interface.

func (Context) Bool

func (c Context) Bool(key string, b bool) Context

Bool adds the field key with val as a bool to the logger context.

func (Context) Bools

func (c Context) Bools(key string, b []bool) Context

Bools adds the field key with val as a []bool to the logger context.

func (Context) Bytes

func (c Context) Bytes(key string, val []byte) Context

Bytes adds the field key with val as a []byte to the logger context.

func (Context) Caller

func (c Context) Caller() Context

func (Context) CallerWithSkipFrameCount

func (c Context) CallerWithSkipFrameCount(skipFrameCount int) Context

func (Context) Dict

func (c Context) Dict(key string, dict *zerolog.Event) Context

Dict adds the field key with the dict to the logger context.

func (Context) Dur

func (c Context) Dur(key string, d time.Duration) Context

Dur adds the fields key with d divided by unit and stored as a float.

func (Context) Durs

func (c Context) Durs(key string, d []time.Duration) Context

Durs adds the fields key with d divided by unit and stored as a float.

func (Context) EmbedObject

func (c Context) EmbedObject(obj zerolog.LogObjectMarshaler) Context

EmbedObject marshals and Embeds an object that implement the LogObjectMarshaler interface.

func (Context) Err

func (c Context) Err(err error) Context

Err adds the field "error" with serialized err to the logger context.

func (Context) Errs

func (c Context) Errs(key string, errs []error) Context

Errs adds the field key with errs as an array of serialized errors to the logger context.

func (Context) Fields

func (c Context) Fields(fields interface{}) Context

Fields is a helper function to use a map or slice to set fields using type assertion. Only map[string]interface{} and []interface{} are accepted. []interface{} must alternate string keys and arbitrary values, and extraneous ones are ignored.

func (Context) Float32

func (c Context) Float32(key string, f float32) Context

Float32 adds the field key with f as a float32 to the logger context.

func (Context) Float64

func (c Context) Float64(key string, f float64) Context

Float64 adds the field key with f as a float64 to the logger context.

func (Context) Floats32

func (c Context) Floats32(key string, f []float32) Context

Floats32 adds the field key with f as a []float32 to the logger context.

func (Context) Floats64

func (c Context) Floats64(key string, f []float64) Context

Floats64 adds the field key with f as a []float64 to the logger context.

func (Context) Hex

func (c Context) Hex(key string, val []byte) Context

Hex adds the field key with val as a hex string to the logger context.

func (Context) IPAddr

func (c Context) IPAddr(key string, ip net.IP) Context

IPAddr adds IPv4 or IPv6 Address to the context

func (Context) IPPrefix

func (c Context) IPPrefix(key string, pfx net.IPNet) Context

IPPrefix adds IPv4 or IPv6 Prefix (address and mask) to the context

func (Context) Int

func (c Context) Int(key string, i int) Context

Int adds the field key with i as a int to the logger context.

func (Context) Int8

func (c Context) Int8(key string, i int8) Context

Int8 adds the field key with i as a int8 to the logger context.

func (Context) Int16

func (c Context) Int16(key string, i int16) Context

Int16 adds the field key with i as a int16 to the logger context.

func (Context) Int32

func (c Context) Int32(key string, i int32) Context

Int32 adds the field key with i as a int32 to the logger context.

func (Context) Int64

func (c Context) Int64(key string, i int64) Context

Int64 adds the field key with i as a int64 to the logger context.

func (Context) Interface

func (c Context) Interface(key string, i interface{}) Context

func (Context) Ints

func (c Context) Ints(key string, i []int) Context

Ints adds the field key with i as a []int to the logger context.

func (Context) Ints8

func (c Context) Ints8(key string, i []int8) Context

Ints8 adds the field key with i as a []int8 to the logger context.

func (Context) Ints16

func (c Context) Ints16(key string, i []int16) Context

Ints16 adds the field key with i as a []int16 to the logger context.

func (Context) Ints32

func (c Context) Ints32(key string, i []int32) Context

Ints32 adds the field key with i as a []int32 to the logger context.

func (Context) Ints64

func (c Context) Ints64(key string, i []int64) Context

Ints64 adds the field key with i as a []int64 to the logger context.

func (Context) Logger

func (c Context) Logger() Logger

Logger returns the logger with the context previously set.

func (Context) MACAddr

func (c Context) MACAddr(key string, ha net.HardwareAddr) Context

MACAddr adds MAC address to the context

func (Context) Object

func (c Context) Object(key string, obj zerolog.LogObjectMarshaler) Context

Object marshals an object that implement the LogObjectMarshaler interface.

func (Context) RawJSON

func (c Context) RawJSON(key string, b []byte) Context

RawJSON adds already encoded JSON to context.

No sanity check is performed on b; it must not contain carriage returns and be valid JSON.

func (Context) Stack

func (c Context) Stack() Context

Stack enables stack trace printing for the error passed to Err().

func (Context) Str

func (c Context) Str(key, val string) Context

Str adds the field key with val as a string to the logger context.

func (Context) Stringer

func (c Context) Stringer(key string, val fmt.Stringer) Context

Stringer adds the field key with val.String() (or null if val is nil) to the logger context.

func (Context) Strs

func (c Context) Strs(key string, vals []string) Context

Strs adds the field key with val as a string to the logger context.

func (Context) Time

func (c Context) Time(key string, t time.Time) Context

Time adds the field key with t formated as string using zerolog.TimeFieldFormat.

func (Context) Times

func (c Context) Times(key string, t []time.Time) Context

Times adds the field key with t formated as string using zerolog.TimeFieldFormat.

func (Context) Timestamp

func (c Context) Timestamp() Context

func (Context) Uint

func (c Context) Uint(key string, i uint) Context

Uint adds the field key with i as a uint to the logger context.

func (Context) Uint8

func (c Context) Uint8(key string, i uint8) Context

Uint8 adds the field key with i as a uint8 to the logger context.

func (Context) Uint16

func (c Context) Uint16(key string, i uint16) Context

Uint16 adds the field key with i as a uint16 to the logger context.

func (Context) Uint32

func (c Context) Uint32(key string, i uint32) Context

Uint32 adds the field key with i as a uint32 to the logger context.

func (Context) Uint64

func (c Context) Uint64(key string, i uint64) Context

Uint64 adds the field key with i as a uint64 to the logger context.

func (Context) Uints

func (c Context) Uints(key string, i []uint) Context

Uints adds the field key with i as a []uint to the logger context.

func (Context) Uints8

func (c Context) Uints8(key string, i []uint8) Context

Uints8 adds the field key with i as a []uint8 to the logger context.

func (Context) Uints16

func (c Context) Uints16(key string, i []uint16) Context

Uints16 adds the field key with i as a []uint16 to the logger context.

func (Context) Uints32

func (c Context) Uints32(key string, i []uint32) Context

Uints32 adds the field key with i as a []uint32 to the logger context.

func (Context) Uints64

func (c Context) Uints64(key string, i []uint64) Context

Uints64 adds the field key with i as a []uint64 to the logger context.

type Event

type Event zerolog.Event

func Dict

func Dict() *Event

func (*Event) AnErr

func (e *Event) AnErr(key string, err error) *Event

AnErr adds the field key with serialized err to the *Event context. If err is nil, no field is added.

func (*Event) Any

func (e *Event) Any(key string, i interface{}) *Event

Any is a wrapper around Event.Interface.

func (*Event) Array

func (e *Event) Array(key string, arr zerolog.LogArrayMarshaler) *Event

func (*Event) Bool

func (e *Event) Bool(key string, b bool) *Event

Bool adds the field key with val as a bool to the *Event context.

func (*Event) Bools

func (e *Event) Bools(key string, b []bool) *Event

Bools adds the field key with val as a []bool to the *Event context.

func (*Event) Bytes

func (e *Event) Bytes(key string, val []byte) *Event

func (*Event) Caller

func (e *Event) Caller(skip ...int) *Event

func (*Event) CallerSkipFrame

func (e *Event) CallerSkipFrame(skip int) *Event

func (*Event) Dict

func (e *Event) Dict(key string, dict *Event) *Event

Dict adds the field key with a dict to the event context. Use zerolog.Dict() to create the dictionary.

func (*Event) Discard

func (e *Event) Discard() *Event

Discard disables the event so Msg(f) won't print it.

func (*Event) Dur

func (e *Event) Dur(key string, d time.Duration) *Event

Dur adds the field key with duration d stored as zerolog.DurationFieldUnit. If zerolog.DurationFieldInteger is true, durations are rendered as integer instead of float.

func (*Event) Durs

func (e *Event) Durs(key string, d []time.Duration) *Event

Durs adds the field key with duration d stored as zerolog.DurationFieldUnit. If zerolog.DurationFieldInteger is true, durations are rendered as integer instead of float.

func (*Event) EmbedObject

func (e *Event) EmbedObject(obj zerolog.LogObjectMarshaler) *Event

EmbedObject marshals an object that implement the LogObjectMarshaler interface.

func (*Event) Err

func (e *Event) Err(err error) *Event

func (*Event) Errs

func (e *Event) Errs(key string, errs []error) *Event

Errs adds the field key with errs as an array of serialized errors to the *Event context.

func (*Event) Fields

func (e *Event) Fields(fields interface{}) *Event

func (*Event) Float32

func (e *Event) Float32(key string, f float32) *Event

Float32 adds the field key with f as a float32 to the *Event context.

func (*Event) Float64

func (e *Event) Float64(key string, f float64) *Event

Float64 adds the field key with f as a float64 to the *Event context.

func (*Event) Floats32

func (e *Event) Floats32(key string, f []float32) *Event

Floats32 adds the field key with f as a []float32 to the *Event context.

func (*Event) Floats64

func (e *Event) Floats64(key string, f []float64) *Event

Floats64 adds the field key with f as a []float64 to the *Event context.

func (*Event) Func

func (e *Event) Func(f func(e *Event)) *Event

Func allows an anonymous func to run only if the event is enabled.

func (*Event) Hex

func (e *Event) Hex(key string, val []byte) *Event

Hex adds the field key with val as a hex string to the *Event context.

func (*Event) IPAddr

func (e *Event) IPAddr(key string, ip net.IP) *Event

IPAddr adds IPv4 or IPv6 Address to the event

func (*Event) IPPrefix

func (e *Event) IPPrefix(key string, pfx net.IPNet) *Event

IPPrefix adds IPv4 or IPv6 Prefix (address and mask) to the event

func (*Event) Int

func (e *Event) Int(key string, i int) *Event

Int adds the field key with i as a int to the *Event context.

func (*Event) Int8

func (e *Event) Int8(key string, i int8) *Event

Int8 adds the field key with i as a int8 to the *Event context.

func (*Event) Int16

func (e *Event) Int16(key string, i int16) *Event

Int16 adds the field key with i as a int16 to the *Event context.

func (*Event) Int32

func (e *Event) Int32(key string, i int32) *Event

Int32 adds the field key with i as a int32 to the *Event context.

func (*Event) Int64

func (e *Event) Int64(key string, i int64) *Event

Int64 adds the field key with i as a int64 to the *Event context.

func (*Event) Interface

func (e *Event) Interface(key string, i interface{}) *Event

Interface adds the field key with i marshaled using reflection.

func (*Event) Ints

func (e *Event) Ints(key string, i []int) *Event

Ints adds the field key with i as a []int to the *Event context.

func (*Event) Ints8

func (e *Event) Ints8(key string, i []int8) *Event

Ints8 adds the field key with i as a []int8 to the *Event context.

func (*Event) Ints16

func (e *Event) Ints16(key string, i []int16) *Event

Ints16 adds the field key with i as a []int16 to the *Event context.

func (*Event) Ints32

func (e *Event) Ints32(key string, i []int32) *Event

Ints32 adds the field key with i as a []int32 to the *Event context.

func (*Event) Ints64

func (e *Event) Ints64(key string, i []int64) *Event

Ints64 adds the field key with i as a []int64 to the *Event context.

func (*Event) MACAddr

func (e *Event) MACAddr(key string, ha net.HardwareAddr) *Event

MACAddr adds MAC address to the event

func (*Event) Msg

func (e *Event) Msg(msg string)

func (*Event) Msgf

func (e *Event) Msgf(format string, v ...interface{})

func (*Event) Object

func (e *Event) Object(key string, obj zerolog.LogObjectMarshaler) *Event

Object marshals an object that implement the LogObjectMarshaler interface.

func (*Event) RawCBOR

func (e *Event) RawCBOR(key string, b []byte) *Event

RawCBOR adds already encoded CBOR to the log line under key.

No sanity check is performed on b Note: The full featureset of CBOR is supported as data will not be mapped to json but stored as data-url

func (*Event) RawJSON

func (e *Event) RawJSON(key string, b []byte) *Event

func (*Event) Send

func (e *Event) Send()

MACAddr adds MAC address to the event

func (*Event) Stack

func (e *Event) Stack() *Event

Stack enables stack trace printing for the error passed to Err().

ErrorStackMarshaler must be set for this method to do something.

func (*Event) Str

func (e *Event) Str(key, val string) *Event

Str adds the field key with val as a string to the *Event context.

func (*Event) Stringer

func (e *Event) Stringer(key string, val fmt.Stringer) *Event

Stringer adds the field key with val.String() (or null if val is nil) to the *Event context.

func (*Event) Stringers

func (e *Event) Stringers(key string, vals []fmt.Stringer) *Event

func (*Event) Strs

func (e *Event) Strs(key string, vals []string) *Event

Strs adds the field key with vals as a []string to the *Event context.

func (*Event) Time

func (e *Event) Time(key string, t time.Time) *Event

Time adds the field key with t formatted as string using zerolog.TimeFieldFormat.

func (*Event) TimeDiff

func (e *Event) TimeDiff(key string, t time.Time, start time.Time) *Event

TimeDiff adds the field key with positive duration between time t and start. If time t is not greater than start, duration will be 0. Duration format follows the same principle as Dur().

func (*Event) Times

func (e *Event) Times(key string, t []time.Time) *Event

Times adds the field key with t formatted as string using zerolog.TimeFieldFormat.

func (*Event) Timestamp

func (e *Event) Timestamp() *Event

Timestamp adds the current local time as UNIX timestamp to the *Event context with the "time" key. To customize the key name, change zerolog.TimestampFieldName.

NOTE: It won't dedupe the "time" key if the *Event (or *Context) has one already.

func (*Event) Type

func (e *Event) Type(key string, val interface{}) *Event

Type adds the field key with val's type using reflection.

func (*Event) Uint

func (e *Event) Uint(key string, i uint) *Event

Uint adds the field key with i as a uint to the *Event context.

func (*Event) Uint8

func (e *Event) Uint8(key string, i uint8) *Event

Uint8 adds the field key with i as a uint8 to the *Event context.

func (*Event) Uint16

func (e *Event) Uint16(key string, i uint16) *Event

Uint16 adds the field key with i as a uint16 to the *Event context.

func (*Event) Uint32

func (e *Event) Uint32(key string, i uint32) *Event

Uint32 adds the field key with i as a uint32 to the *Event context.

func (*Event) Uint64

func (e *Event) Uint64(key string, i uint64) *Event

Uint64 adds the field key with i as a uint64 to the *Event context.

func (*Event) Uints

func (e *Event) Uints(key string, i []uint) *Event

Uints adds the field key with i as a []int to the *Event context.

func (*Event) Uints8

func (e *Event) Uints8(key string, i []uint8) *Event

Uints8 adds the field key with i as a []int8 to the *Event context.

func (*Event) Uints16

func (e *Event) Uints16(key string, i []uint16) *Event

Uints16 adds the field key with i as a []int16 to the *Event context.

func (*Event) Uints32

func (e *Event) Uints32(key string, i []uint32) *Event

Uints32 adds the field key with i as a []int32 to the *Event context.

func (*Event) Uints64

func (e *Event) Uints64(key string, i []uint64) *Event

Uints64 adds the field key with i as a []int64 to the *Event context.

type Level

type Level zerolog.Level

Level defines log levels.

type Logger

type Logger zerolog.Logger

func Ctx

func Ctx(ctx context.Context) *Logger

func New

func New(w io.Writer) Logger

func Nop

func Nop() Logger

Nop returns a disabled logger for which all operation are no-op.

func (*Logger) Debug

func (l *Logger) Debug() *Event

Debug starts a new message with debug level.

You must call Msg on the returned event in order to send the event.

func (*Logger) Err

func (l *Logger) Err(err error) *Event

func (*Logger) Error

func (l *Logger) Error() *Event

func (*Logger) Fatal

func (l *Logger) Fatal() *Event

func (Logger) GetLevel

func (l Logger) GetLevel() Level

GetLevel returns the current Level of l.

func (Logger) Hook

func (l Logger) Hook(h zerolog.Hook) Logger

Hook returns a logger with the h Hook.

func (*Logger) Info

func (l *Logger) Info() *Event

Info starts a new message with info level.

You must call Msg on the returned event in order to send the event.

func (Logger) Level

func (l Logger) Level(lvl zerolog.Level) Logger

Level creates a child logger with the minimum accepted level set to level.

func (*Logger) Log

func (l *Logger) Log() *Event

func (Logger) Output

func (l Logger) Output(w io.Writer) Logger

Output duplicates the current logger and sets w as its output.

func (*Logger) Panic

func (l *Logger) Panic() *Event

func (*Logger) PointerToStd

func (logger *Logger) PointerToStd() *stdLogger

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func (Logger) Sample

func (l Logger) Sample(s zerolog.Sampler) Logger

Sample returns a logger with the s sampler.

func (Logger) ToStd

func (logger Logger) ToStd() stdLogger

func (*Logger) Trace

func (l *Logger) Trace() *Event

Trace starts a new message with trace level.

You must call Msg on the returned event in order to send the event.

func (*Logger) UpdateContext

func (l *Logger) UpdateContext(update func(c Context) Context)

UpdateContext updates the internal logger's context.

Use this method with caution. If unsure, prefer the With method.

func (*Logger) Warn

func (l *Logger) Warn() *Event

Warn starts a new message with warn level.

You must call Msg on the returned event in order to send the event.

func (Logger) With

func (l Logger) With() Context

With creates a child logger with the field added to its context.

func (Logger) WithContext

func (l Logger) WithContext(ctx context.Context) context.Context

func (*Logger) WithLevel

func (l *Logger) WithLevel(level zerolog.Level) *Event

func (Logger) Write

func (l Logger) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. This is useful to set as a writer for the standard library log.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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