log

package
v2.3.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Bug

func Bug() *zerolog.Event

Bug starts a new message with "bug" level

See Logger.Bug()

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

func BugWithSampler

func BugWithSampler(lg *Logger, sampler zerolog.Sampler) *zerolog.Event

BugWithSampler is like Bug() but without auto-sampler logic

In most cases, using Bug() directly should be preferred.

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 Debugf

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

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

func Debugln

func Debugln(v ...interface{})

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

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 Errorf

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

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

func Errorln

func Errorln(v ...interface{})

Errorln sends a log event using error level and no extra field. Arguments are handled in the manner of fmt.Println.

func Fatal

func Fatal() *zerolog.Event

Fatal starts a new message with fatal level.

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

func Fatalf

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

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

func Fatalln

func Fatalln(v ...interface{})

Fatalln sends a log event using fatal level and no extra field. Arguments are handled in the manner of fmt.Println.

func GetAutosampler

func GetAutosampler() zerolog.Sampler

GetAutosampler returns a sampler based on caller's caller location.

Samplers are created using NewRatelimitingSampler().

In most cases, this function should not be used directly, unless implementing some other helpers similar to Autosample() or Bug().

func GetLevel

func GetLevel() zerolog.Level

GetLevel returns the global logger level.

func GetPrettyConsoleWriter

func GetPrettyConsoleWriter() io.Writer

GetPrettyConsoleWriter returns a pretty console writer.

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 Infof

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

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

func Infoln

func Infoln(v ...interface{})

Infoln sends a log event using info level and no extra field. Arguments are handled in the manner of fmt.Println.

func Log

func Log() *zerolog.Event

Log starts a new message with no level. This is equivalent to using WithLevel(NoLevel).

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

func NewRatelimitingSampler

func NewRatelimitingSampler() zerolog.Sampler

NewRatelimitingSampler return a log sampler that allows max one log entry per few seconds.

Use to report cases when we want to warn for visibility, but the warning is likely to reoccur, and we do not want to spam logs. Eg. Invalid arguments on some intra-aperture RPC call.

This should be preferred over log.Sample(zerolog.Sometimes), so that we can be sure that one-off or low-frequency cases are always logged. It's preferred to create a new Sampler for each kind of Msg you send.

See also Logger.Autosample()

Note: Return value should be persisted – do not pass directly to log.Sample().

func NewZapAdapter

func NewZapAdapter(logger *Logger, component string) zapcore.Core

NewZapAdapter returns a new zapcore Core logger interface that converts given logger's io.writer to WriteSyncer.

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 Panicf

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

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

func Panicln

func Panicln(v ...interface{})

Panicln sends a log event using panic level and no extra field. Arguments are handled in the manner of fmt.Println.

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 Println

func Println(v ...interface{})

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

func SetGlobalLevel

func SetGlobalLevel(level zerolog.Level)

SetGlobalLevel sets the global log level with given level.

func SetGlobalLevelString

func SetGlobalLevelString(levelString string) error

SetGlobalLevelString parses given levelString and sets the global log level.

func SetGlobalLogger

func SetGlobalLogger(lg *Logger)

SetGlobalLogger closes the previous global logger and sets given logger as a new global logger.

func SetStdLogger

func SetStdLogger(lg *Logger)

SetStdLogger sets output for the standard logger.

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 WaitFlush

func WaitFlush()

WaitFlush waits a few ms to let the the buffer to flush.

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 Warnf

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

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

func Warnln

func Warnln(v ...interface{})

Warnln sends a log event using warn level and no extra field. Arguments are handled in the manner of fmt.Println.

func With

func With() zerolog.Context

With creates a child logger of the global 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.

func Write

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

Write implements io.Writer interface.

Types

type Logger

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

Logger is wrapper around zerolog.Logger and io.writers.

func Autosample

func Autosample() *Logger

Autosample returns the global logger with sampler based on caller location.

See Logger.Autosample().

func GetGlobalLogger

func GetGlobalLogger() *Logger

GetGlobalLogger returns the global logger.

func Hook

func Hook(hook zerolog.Hook) *Logger

Hook returns the global logger with the h hook.

func Level

func Level(level zerolog.Level) *Logger

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

func NewDefaultLogger

func NewDefaultLogger() *Logger

NewDefaultLogger creates a new default logger with default settings.

func NewLogger

func NewLogger(w io.Writer, levelString string) *Logger

NewLogger creates a new logger.

func NewLoggerWithWriters

func NewLoggerWithWriters(w io.Writer, writers []io.Writer, levelString string) *Logger

NewLoggerWithWriters creates a new logger instance and stores a list of additional io.Writers.

func Output

func Output(w io.Writer) *Logger

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

func Sample

func Sample(sampler zerolog.Sampler) *Logger

Sample returns the global logger with the s sampler.

func WithBool

func WithBool(key string, value bool) *Logger

WithBool adds a bool to the global logger context.

func WithComponent

func WithComponent(component string) *Logger

WithComponent enables the global logger to chain loggers with additional context, component name.

func WithInterface

func WithInterface(key string, value interface{}) *Logger

WithInterface adds an interface to the global logger context.

func WithStr

func WithStr(key string, value string) *Logger

WithStr adds a string to the global logger context.

func (*Logger) Autosample

func (lg *Logger) Autosample() *Logger

Autosample returns the current logger with sampler based on caller location.

Sampler will be created using NewRatelimitingSampler()

This is basically shorthand for:

```go var mySampler = NewRatelimitingSampler() ... Logger.Sample(mySampler) ```

The "auto" part has a slight runtime cost though, so the full should be preferred for cases where performance matters, like on datapath.

func (*Logger) Bug

func (lg *Logger) Bug() *zerolog.Event

Bug starts a new message with "bug" level

"Bug" is the same level as "warn", but it is intended for programmer's errors, where normally you'd want to use "panic", but: * error is not affecting the service as-a-whole, * there's reasonable way to continue, * restarting service won't fix the error.

You might want to use Bug() for cases like hitting "impossible" case of a switch in an rpc call, or similar.

Additionally, every callsite of Bug will be automatically ratelimited (like with Autosample).

Also, automatic bug-reporting may be integrated here.

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

func (*Logger) CloseWriters

func (lg *Logger) CloseWriters()

CloseWriters iterate over a list of additional writers to close them.

func (*Logger) Debug

func (lg *Logger) 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 (*Logger) Debugf

func (lg *Logger) Debugf(format string, v ...interface{})

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

func (*Logger) Debugln

func (lg *Logger) Debugln(v ...interface{})

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

func (*Logger) Error

func (lg *Logger) 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 (*Logger) Errorf

func (lg *Logger) Errorf(format string, v ...interface{})

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

func (*Logger) Errorln

func (lg *Logger) Errorln(v ...interface{})

Errorln sends a log event using error level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*Logger) Fatal

func (lg *Logger) Fatal() *zerolog.Event

Fatal starts a new message with fatal level. This is an alias for Panic.

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

func (*Logger) Fatalf

func (lg *Logger) Fatalf(format string, v ...interface{})

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

func (*Logger) Fatalln

func (lg *Logger) Fatalln(v ...interface{})

Fatalln sends a log event using fatal level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*Logger) GetLevel

func (lg *Logger) GetLevel() zerolog.Level

GetLevel returns the current logger level.

func (*Logger) GetZerolog

func (lg *Logger) GetZerolog() *zerolog.Logger

GetZerolog returns underlying zerolog logger.

func (*Logger) Hook

func (lg *Logger) Hook(hook zerolog.Hook) *Logger

Hook returns the current logger with the h hook.

func (*Logger) Info

func (lg *Logger) 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 (*Logger) Infof

func (lg *Logger) Infof(format string, v ...interface{})

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

func (*Logger) Infoln

func (lg *Logger) Infoln(v ...interface{})

Infoln sends a log event using info level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*Logger) Level

func (lg *Logger) Level(level zerolog.Level) *Logger

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

func (*Logger) Log

func (lg *Logger) Log() *zerolog.Event

Log starts a new message with no level. This is equivalent to using lg.WithLevel(NoLevel).

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

func (*Logger) NewFromZerolog

func (lg *Logger) NewFromZerolog(logger *zerolog.Logger) *Logger

NewFromZerolog creates the logger from zerolog instance.

func (*Logger) Output

func (lg *Logger) Output(w io.Writer) *Logger

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

func (*Logger) Panic

func (lg *Logger) Panic() *zerolog.Event

Panic starts a new message with panic level. The panic() function is called by the Msg method, which stops the ordinary flow of a goroutine and invokes any registered PanicHandler.

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

func (*Logger) Panicf

func (lg *Logger) Panicf(format string, v ...interface{})

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

func (*Logger) Panicln

func (lg *Logger) Panicln(v ...interface{})

Panicln sends a log event using panic level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*Logger) Print

func (lg *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 (lg *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) Println

func (lg *Logger) Println(v ...interface{})

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

func (*Logger) Sample

func (lg *Logger) Sample(sampler zerolog.Sampler) *Logger

Sample returns the current logger with the s sampler.

func (*Logger) Trace

func (lg *Logger) 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 (*Logger) Warn

func (lg *Logger) 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 (*Logger) Warnf

func (lg *Logger) Warnf(format string, v ...interface{})

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

func (*Logger) Warnln

func (lg *Logger) Warnln(v ...interface{})

Warnln sends a log event using warn level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*Logger) With

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

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

func (*Logger) WithBool

func (lg *Logger) WithBool(key string, value bool) *Logger

WithBool adds a bool to the logger context.

func (*Logger) WithComponent

func (lg *Logger) WithComponent(component string) *Logger

WithComponent enables the current logger to chain loggers with additional context, component name.

func (*Logger) WithInterface

func (lg *Logger) WithInterface(key string, value interface{}) *Logger

WithInterface adds an interface to the logger context.

func (*Logger) WithLevel

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

WithLevel starts a new message with level. Unlike Fatal and Panic methods, WithLevel does not terminate the program or stop the ordinary flow of a goroutine when used with their respective levels.

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

func (*Logger) WithStr

func (lg *Logger) WithStr(key string, value string) *Logger

WithStr adds a string to the logger context.

func (*Logger) Write

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

Write implements io.Writer interface.

Jump to

Keyboard shortcuts

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