logger

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: GPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v0.0.3

func Init(ctx context.Context, cfg Config) error

Init constructs a logger using New and makes it globally available via package-level helpers.

func Use added in v0.0.3

func Use(log *Logger)

Use replaces the global logger instance with the provided implementation.

func With added in v0.0.3

func With() zerolog.Context

With returns a context for adding fields to the global logger.

Types

type Config

type Config struct {
	Enabled     bool
	Level       string `default:"info"`
	Environment string `default:"development"`
	ServiceName string `default:"unknown-service"`
	Console     bool   `default:"true"`
	Writers     []io.Writer
	OTLP        OTLPConfig
	File        FileConfig
	UseGlobal   bool
}

Config drives logger construction without importing the logging implementation details.

func (Config) ApplyDefaults added in v0.0.3

func (c Config) ApplyDefaults() Config

ApplyDefaults returns a copy of the config with default values populated.

func (Config) Validate added in v0.0.3

func (c Config) Validate() error

Validate ensures the logger configuration is complete when logging is enabled.

type Event added in v0.0.5

type Event struct {
	*zerolog.Event
}

Event wraps zerolog.Event to intercept Err() for stack trace injection.

func Debug added in v0.0.3

func Debug() *Event

Debug opens a debug event through the global logger.

func Error added in v0.0.3

func Error() *Event

Error opens an error event through the global logger.

func Fatal added in v0.0.3

func Fatal() *Event

Fatal opens a fatal event through the global logger.

func Info added in v0.0.3

func Info() *Event

Info opens an info event through the global logger.

func Warn added in v0.0.3

func Warn() *Event

Warn opens a warn event through the global logger.

func WithLevel added in v0.0.5

func WithLevel(level zerolog.Level) *Event

WithLevel opens an event at the specified level through the global logger.

func (*Event) AnErr added in v0.0.5

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

AnErr adds an error field with a custom key.

func (*Event) Any added in v0.0.5

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

Any adds an interface{} field.

func (*Event) Array added in v0.0.5

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

Array adds an array field.

func (*Event) Bool added in v0.0.5

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

Bool adds a bool field.

func (*Event) Bools added in v0.0.5

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

Bools adds a bool array field.

func (*Event) Bytes added in v0.0.5

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

Bytes adds a bytes field.

func (*Event) Caller added in v0.0.5

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

Caller adds the file:line of the caller.

func (*Event) Ctx added in v0.0.5

func (e *Event) Ctx(ctx context.Context) *Event

Ctx adds context to the event.

func (*Event) Dict added in v0.0.5

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

Dict adds a sub-dictionary.

func (*Event) Discard added in v0.0.5

func (e *Event) Discard() *Event

Discard disables the event.

func (*Event) Dur added in v0.0.5

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

Dur adds a duration field.

func (*Event) Durs added in v0.0.5

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

Durs adds a duration array field.

func (*Event) EmbedObject added in v0.0.5

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

EmbedObject embeds an object.

func (*Event) Enabled added in v0.0.5

func (e *Event) Enabled() bool

Enabled returns whether the event is enabled.

func (*Event) Err added in v0.0.5

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

Err wraps the error with stack trace if needed before logging.

func (*Event) Errs added in v0.0.5

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

Errs adds a slice of errors field.

func (*Event) Float32 added in v0.0.5

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

Float32 adds a float32 field.

func (*Event) Float64 added in v0.0.5

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

Float64 adds a float64 field.

func (*Event) Floats32 added in v0.0.5

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

Floats32 adds a float32 array field.

func (*Event) Floats64 added in v0.0.5

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

Floats64 adds a float64 array field.

func (*Event) Hex added in v0.0.5

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

Hex adds a hex-encoded bytes field.

func (*Event) Int added in v0.0.5

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

Int adds an int field.

func (*Event) Int16 added in v0.0.5

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

Int16 adds an int16 field.

func (*Event) Int32 added in v0.0.5

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

Int32 adds an int32 field.

func (*Event) Int64 added in v0.0.5

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

Int64 adds an int64 field.

func (*Event) Int8 added in v0.0.5

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

Int8 adds an int8 field.

func (*Event) Interface added in v0.0.5

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

Interface adds an interface{} field.

func (*Event) Ints added in v0.0.5

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

Ints adds an int array field.

func (*Event) Object added in v0.0.5

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

Object marshals an object.

func (*Event) RawJSON added in v0.0.5

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

RawJSON adds a pre-encoded JSON field.

func (*Event) Stack added in v0.0.5

func (e *Event) Stack() *Event

Stack enables stack trace printing.

func (*Event) Str added in v0.0.5

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

Str adds a string field.

func (*Event) Strs added in v0.0.5

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

Strs adds a string array field.

func (*Event) Time added in v0.0.5

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

Time adds a time field.

func (*Event) TimeDiff added in v0.0.5

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

TimeDiff adds a duration field representing the difference between two times.

func (*Event) Times added in v0.0.5

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

Times adds a time array field.

func (*Event) Timestamp added in v0.0.5

func (e *Event) Timestamp() *Event

Timestamp adds the current timestamp.

func (*Event) Uint added in v0.0.5

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

Uint adds a uint field.

func (*Event) Uint16 added in v0.0.5

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

Uint16 adds a uint16 field.

func (*Event) Uint32 added in v0.0.5

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

Uint32 adds a uint32 field.

func (*Event) Uint64 added in v0.0.5

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

Uint64 adds a uint64 field.

func (*Event) Uint8 added in v0.0.5

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

Uint8 adds a uint8 field.

func (*Event) Uints added in v0.0.5

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

Uints adds a uint array field.

type FileConfig added in v0.0.3

type FileConfig struct {
	Enabled   bool
	Directory string `validate:"required_if=Enabled true"`
	Buffer    int    `default:"1024" validate:"omitempty,gt=0"`
}

FileConfig controls optional file-based logging.

type Logger

type Logger struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

Logger wraps zerolog.Logger with trace metadata injection and resource management.

func Global added in v0.0.3

func Global() *Logger

Global returns the current global logger reference. Panics if logger has not been initialized via Init() or Use().

func New

func New(ctx context.Context, cfg Config) (*Logger, error)

New constructs a Zerolog-backed logger based on the provided configuration.

func (*Logger) Close added in v0.0.5

func (l *Logger) Close() error

Close shuts down the logger and releases any resources including file handles and background goroutines.

func (*Logger) Debug

func (l *Logger) Debug() *Event

Debug opens a debug level event.

func (*Logger) Err added in v0.0.5

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

Err opens an error level event with the given error wrapped with stack trace.

func (*Logger) Error

func (l *Logger) Error() *Event

Error opens an error level event.

func (*Logger) Fatal

func (l *Logger) Fatal() *Event

Fatal opens a fatal level event.

func (*Logger) Info

func (l *Logger) Info() *Event

Info opens an info level event.

func (*Logger) Warn

func (l *Logger) Warn() *Event

Warn opens a warn level event.

func (*Logger) With

func (l *Logger) With() zerolog.Context

With returns a context for adding fields to the logger.

func (*Logger) WithLevel added in v0.0.5

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

WithLevel opens an event at the specified level.

type OTLPConfig added in v0.0.3

type OTLPConfig struct {
	Enabled     bool
	Endpoint    string `validate:"required_if=Enabled true"`
	Insecure    bool
	Headers     map[string]string
	Timeout     time.Duration `default:"5s" validate:"omitempty,gt=0"`
	Exporter    string        `default:"http" validate:"oneof=http grpc"`
	Credentials auth.Credentials
	Async       bool
	UseSpool    bool
	QueueDir    string
}

OTLPConfig captures OTLP export settings for log delivery. Endpoint accepts a base URL (host[:port] with optional path). When a scheme is provided, TLS is inferred automatically (http => insecure, https => secure). Without a scheme, the Insecure flag determines whether TLS is disabled.

Jump to

Keyboard shortcuts

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