Documentation ¶
Overview ¶
Package zwrap provides a wrapper for zerolog.Logger that implements the standard library's log.Logger methods, as well as other common logging methods as an attempt to provide compatibility with other logging libraries.
Index ¶
- Variables
- func Colorize(s interface{}, c int, disabled bool) string
- func LogLevelFmt(noColor bool) zerolog.Formatter
- type GRPCCompatLogger
- type Level
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) ForceLevel(level any)
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) Logf(format string, v ...interface{})
- func (l *Logger) NoFatals(b bool)
- func (l *Logger) NoPanics(b bool)
- func (l *Logger) Noticef(format string, v ...interface{})
- func (l *Logger) Output(calldepth int, s string) error
- func (l *Logger) Panic(v ...interface{})
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicln(v ...interface{})
- func (l *Logger) Prefix() string
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) SetLevel(level any)
- func (l *Logger) SetPrefix(prefix string)
- func (l *Logger) SetPrintLevel(level zerolog.Level)
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Traceln(v ...interface{})
- func (l *Logger) V(level int) bool
- func (l *Logger) Verbosef(format string, v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warning(args ...any)
- func (l *Logger) Warningf(format string, v ...interface{})
- func (l *Logger) Warningln(args ...any)
- func (l *Logger) Warnln(v ...interface{})
- func (l *Logger) WithFields(fields map[string]interface{}) *Logger
- func (l *Logger) WithForceLevel(level any) *Logger
- func (l *Logger) WithNoFatals() *Logger
- func (l *Logger) WithNoPanics() *Logger
- func (l *Logger) WithPrefix(prefix string) *Logger
- func (l *Logger) Write(p []byte) (n int, err error)
- func (l *Logger) ZLogger() *zerolog.Logger
- type StdCompatLogger
- type ZWrapLogger
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var FormattedLevels = map[zerolog.Level]string{ zerolog.TraceLevel: "TRC", zerolog.DebugLevel: "DBG", zerolog.InfoLevel: "INF", zerolog.WarnLevel: "WRN", zerolog.ErrorLevel: "ERR", zerolog.FatalLevel: "FTL", zerolog.PanicLevel: "PNC", }
FormattedLevels are used by ConsoleWriter's consoleDefaultFormatLevel for a short level name.
View Source
var LevelColors = map[zerolog.Level]int{ zerolog.TraceLevel: colorMagenta, zerolog.DebugLevel: colorYellow, zerolog.InfoLevel: colorGreen, zerolog.WarnLevel: colorRed, zerolog.ErrorLevel: colorRed, zerolog.FatalLevel: colorRed, zerolog.PanicLevel: colorRed, }
Functions ¶
func Colorize ¶ added in v0.4.4
Colorize returns the string s wrapped in ANSI code c, unless disabled is true or c is 0.
func LogLevelFmt ¶ added in v0.4.4
Types ¶
type GRPCCompatLogger ¶ added in v0.5.0
type GRPCCompatLogger interface { Info(args ...any) Infoln(args ...any) Infof(format string, args ...any) Warning(args ...any) Warningln(args ...any) Warningf(format string, args ...any) Error(args ...any) Errorln(args ...any) Errorf(format string, args ...any) Fatal(args ...any) Fatalln(args ...any) Fatalf(format string, args ...any) V(l int) bool }
type Logger ¶
func Wrap ¶
Example ¶
// Create a new zerolog.Logger logger := zerolog.New(os.Stderr).With().Timestamp().Logger() // Demonstrate that we can use the stdlib logger myThing := &needsLogger{} myThing.SetLogger(log.New(os.Stderr, "stdlog: ", log.LstdFlags)) myThing.DoSomething() // Demonstrate that we can use zerolog when wrapped /* Before, does not compile: myThing.SetLogger(logger) myThing.DoSomething() */ // The zwrap solution, wrap the logger: zl := Wrap(logger) myThing.SetLogger(zl) myThing.DoSomething()
Output:
func (*Logger) ForceLevel ¶ added in v0.6.0
func (*Logger) SetLevel ¶ added in v0.4.2
SetLevel is compatibility for ghettovoice/gosip/log.Logger
func (*Logger) SetPrintLevel ¶
func (*Logger) WithFields ¶ added in v0.4.2
func (*Logger) WithForceLevel ¶ added in v0.6.0
func (*Logger) WithNoFatals ¶ added in v0.6.0
func (*Logger) WithNoPanics ¶ added in v0.6.0
func (*Logger) WithPrefix ¶ added in v0.4.2
type StdCompatLogger ¶
type StdCompatLogger interface { Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Fatalln(v ...interface{}) Panic(v ...interface{}) Panicf(format string, v ...interface{}) Panicln(v ...interface{}) Prefix() string Print(v ...interface{}) Printf(format string, v ...interface{}) Println(v ...interface{}) SetPrefix(prefix string) Output(calldepth int, s string) error }
StdCompatLogger is an interface that provides compatibility with the standard library's log.Logger.
type ZWrapLogger ¶ added in v0.6.2
type ZWrapLogger interface { StdCompatLogger GRPCCompatLogger }
Click to show internal directories.
Click to hide internal directories.