log

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package log provides a global logger for zerolog.

Index

Constants

This section is empty.

Variables

View Source
var Clogger = zerolog.New(os.Stderr).With().Timestamp().Logger()

Current Logger is the global logger.

Functions

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the Logger associated with the ctx. If no logger is associated, a disabled logger is returned.

func Debug

func Debug() *zerolog.Event

Debug starts a new message with debug level.

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

func Err

func Err(err error) *zerolog.Event

Err starts a new message with error level with err as a field if not nil or with info level if err is nil.

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

func Error

func Error() *zerolog.Event

Error starts a new message with error level.

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

func Fatal

func Fatal() *zerolog.Event

Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method.

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

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

func Info

func Info() *zerolog.Event

Info starts a new message with info level.

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

func Level

func Level(level zerolog.Level) zerolog.Logger

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

func Log

func Log() *zerolog.Event

Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.

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

func Output

func Output(w io.Writer) zerolog.Logger

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

func Panic

func Panic() *zerolog.Event

Panic starts a new message with panic level. The message is also sent to the panic function.

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

func Print

func 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 Printf

func 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 Sample

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func Service

func Service(ctx context.Context, source, msg string, err error, params map[string]interface{})

Service logs using info - source, msg, error, params

func SetupLogging

func SetupLogging(level string, isConsole, isCaller bool)

InitLog initializes global logging settings level - debug, info, warn, error, fatal, panic, none

func Trace

func Trace() *zerolog.Event

Trace starts a new message with trace level.

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

func UpdateContext

func UpdateContext(update func(c zerolog.Context) zerolog.Context)

UpdateContext updates the internal logger's context.

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

func Warn

func Warn() *zerolog.Event

Warn starts a new message with warn level.

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

func With

func With() zerolog.Context

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

func WithLevel

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

WithLevel starts a new message with level.

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

Types

type EventReceiver

type EventReceiver struct{}

EventReceiver is a sentinel EventReceiver uses zerolog to log events

func (*EventReceiver) Event

func (n *EventReceiver) Event(eventName string)

Event receives a simple notification when various events occur.

func (*EventReceiver) EventErr

func (n *EventReceiver) EventErr(eventName string, err error) error

EventErr receives a notification of an error if one occurs.

func (*EventReceiver) EventErrKv

func (n *EventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error

EventErrKv receives a notification of an error if one occurs along with optional key/value data.

func (*EventReceiver) EventKv

func (n *EventReceiver) EventKv(eventName string, kvs map[string]string)

EventKv receives a notification when various events occur along with optional key/value data.

func (*EventReceiver) Timing

func (n *EventReceiver) Timing(eventName string, nanos int64)

Timing receives the time an event took to happen.

func (*EventReceiver) TimingKv

func (n *EventReceiver) TimingKv(eventName string, nanos int64, kvs map[string]string)

TimingKv receives the time an event took to happen along with optional key/value data.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

type LogrusLogger

type LogrusLogger interface {
	Panic(v ...interface{})
	Panicf(format string, v ...interface{})
	Panicln(v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Fatalln(v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Errorln(v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Warnln(v ...interface{})
	Warning(v ...interface{})
	Warningf(format string, v ...interface{})
	Warningln(v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Infoln(v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Debugln(v ...interface{})
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
	Trace(v ...interface{})
	Tracef(format string, v ...interface{})
	Traceln(v ...interface{})
	V(verbosity int) bool
	SetLevel(lvl zerolog.Level)
	GetLevel() zerolog.Level
	WithField(key string, value interface{}) zerolog.Context
	WithFields(fields map[string]interface{}) zerolog.Context
}

func NewLogrus

func NewLogrus(log zerolog.Logger) LogrusLogger

type StdLogger

type StdLogger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
	Printf(format string, v ...interface{})
}

func NewStd

func NewStd(log zerolog.Logger) StdLogger

Jump to

Keyboard shortcuts

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