Documentation ¶
Index ¶
- Constants
- func Bug() *zerolog.Event
- func BugWithSampler(lg *Logger, sampler zerolog.Sampler) *zerolog.Event
- func Debug() *zerolog.Event
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func Error() *zerolog.Event
- func Errorf(format string, v ...interface{})
- func Errorln(v ...interface{})
- func Fatal() *zerolog.Event
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func GetAutosampler() zerolog.Sampler
- func GetLevel() zerolog.Level
- func GetPrettyConsoleWriter() io.Writer
- func Info() *zerolog.Event
- func Infof(format string, v ...interface{})
- func Infoln(v ...interface{})
- func Log() *zerolog.Event
- func NewRatelimitingSampler() zerolog.Sampler
- func NewZapAdapter(logger *Logger, component string) zapcore.Core
- func Panic() *zerolog.Event
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetGlobalLevel(level zerolog.Level)
- func SetGlobalLevelString(levelString string) error
- func SetGlobalLogger(lg *Logger)
- func SetStdLogger(lg *Logger)
- func Trace() *zerolog.Event
- func WaitFlush()
- func Warn() *zerolog.Event
- func Warnf(format string, v ...interface{})
- func Warnln(v ...interface{})
- func With() zerolog.Context
- func WithLevel(level zerolog.Level) *zerolog.Event
- func Write(p []byte) (n int, err error)
- type Logger
- func Autosample() *Logger
- func GetGlobalLogger() *Logger
- func Hook(hook zerolog.Hook) *Logger
- func Level(level zerolog.Level) *Logger
- func NewDefaultLogger() *Logger
- func NewLogger(w io.Writer, levelString string) *Logger
- func NewLoggerWithWriters(w io.Writer, writers []io.Writer, levelString string) *Logger
- func Output(w io.Writer) *Logger
- func Sample(sampler zerolog.Sampler) *Logger
- func WithBool(key string, value bool) *Logger
- func WithComponent(component string) *Logger
- func WithInterface(key string, value interface{}) *Logger
- func WithStr(key string, value string) *Logger
- func (lg *Logger) Autosample() *Logger
- func (lg *Logger) Bug() *zerolog.Event
- func (lg *Logger) CloseWriters()
- func (lg *Logger) Debug() *zerolog.Event
- func (lg *Logger) Debugf(format string, v ...interface{})
- func (lg *Logger) Debugln(v ...interface{})
- func (lg *Logger) Error() *zerolog.Event
- func (lg *Logger) Errorf(format string, v ...interface{})
- func (lg *Logger) Errorln(v ...interface{})
- func (lg *Logger) Fatal() *zerolog.Event
- func (lg *Logger) Fatalf(format string, v ...interface{})
- func (lg *Logger) Fatalln(v ...interface{})
- func (lg *Logger) GetLevel() zerolog.Level
- func (lg *Logger) GetZerolog() *zerolog.Logger
- func (lg *Logger) Hook(hook zerolog.Hook) *Logger
- func (lg *Logger) Info() *zerolog.Event
- func (lg *Logger) Infof(format string, v ...interface{})
- func (lg *Logger) Infoln(v ...interface{})
- func (lg *Logger) Level(level zerolog.Level) *Logger
- func (lg *Logger) Log() *zerolog.Event
- func (lg *Logger) NewFromZerolog(logger *zerolog.Logger) *Logger
- func (lg *Logger) Output(w io.Writer) *Logger
- func (lg *Logger) Panic() *zerolog.Event
- func (lg *Logger) Panicf(format string, v ...interface{})
- func (lg *Logger) Panicln(v ...interface{})
- func (lg *Logger) Print(v ...interface{})
- func (lg *Logger) Printf(format string, v ...interface{})
- func (lg *Logger) Println(v ...interface{})
- func (lg *Logger) Sample(sampler zerolog.Sampler) *Logger
- func (lg *Logger) Trace() *zerolog.Event
- func (lg *Logger) Warn() *zerolog.Event
- func (lg *Logger) Warnf(format string, v ...interface{})
- func (lg *Logger) Warnln(v ...interface{})
- func (lg *Logger) With() zerolog.Context
- func (lg *Logger) WithBool(key string, value bool) *Logger
- func (lg *Logger) WithComponent(component string) *Logger
- func (lg *Logger) WithInterface(key string, value interface{}) *Logger
- func (lg *Logger) WithLevel(level zerolog.Level) *zerolog.Event
- func (lg *Logger) WithStr(key string, value string) *Logger
- func (lg *Logger) Write(p []byte) (n int, err error)
Constants ¶
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 ¶
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 ¶
BugWithSampler is like Bug() but without auto-sampler logic
In most cases, using Bug() directly should be preferred.
func Debug ¶
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 ¶
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 ¶
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 ¶
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 GetPrettyConsoleWriter ¶
GetPrettyConsoleWriter returns a pretty console writer.
func Info ¶
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 ¶
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 ¶
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 ¶
NewZapAdapter returns a new zapcore Core logger interface that converts given logger's io.writer to WriteSyncer.
func Panic ¶
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 ¶
SetGlobalLevel sets the global log level with given level.
func SetGlobalLevelString ¶
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 Trace ¶
Trace starts a new message with trace level.
You must call Msg on the returned event in order to send the event.
func Warn ¶
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.
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 Level ¶
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 NewLoggerWithWriters ¶
NewLoggerWithWriters creates a new logger instance and stores a list of additional io.Writers.
func WithComponent ¶
WithComponent enables the global logger to chain loggers with additional context, component name.
func WithInterface ¶
WithInterface adds an interface to the global logger context.
func (*Logger) Autosample ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) GetZerolog ¶
GetZerolog returns underlying zerolog logger.
func (*Logger) Info ¶
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 ¶
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 ¶
Level creates a child logger of the current logger with the minimum accepted level set to level.
func (*Logger) Log ¶
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 ¶
NewFromZerolog creates the logger from zerolog instance.
func (*Logger) Panic ¶
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 ¶
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 ¶
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) Trace ¶
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 ¶
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 ¶
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 ¶
With creates a child logger of the current logger with the field added to its context.
func (*Logger) WithComponent ¶
WithComponent enables the current logger to chain loggers with additional context, component name.
func (*Logger) WithInterface ¶
WithInterface adds an interface to the logger context.
func (*Logger) WithLevel ¶
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.