Documentation
¶
Overview ¶
Package logger has helpers to setup a zerolog.Logger
https://github.com/rs/zerolog
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New is a convenience function to initialize a zerolog.Logger with an initial minimum accepted level and timestamp (if true) for a given io.Writer.
func NewWithGCPHook ¶
NewWithGCPHook is a convenience function to initialize a zerolog.Logger with an initial minimum accepted level and timestamp (if true) for a given io.Writer. In addition, it adds a Google Cloud Platform (GCP) Severity Hook. Zerolog by default outputs structured logs with "level":"error" as its leveling. Google Cloud, as an example, expects "severity","ERROR" for its leveling. This hook will add severity to each message.
Example ¶
lgr := NewWithGCPHook(os.Stdout, zerolog.DebugLevel, false)
lgr.Trace().Msg("Trace is lower than Debug, this message is filtered out")
lgr.Debug().Msg("This is a log at the Debug level")
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
lgr.Debug().Msg("Logging level raised to Error, Debug is lower than Error, this message is filtered out")
lgr.Error().Msg("This is a log at the Error level")
zerolog.SetGlobalLevel(zerolog.TraceLevel)
lgr.Trace().Msg("Setting Global level will not impact minimum set to logger, this trace message will still be filtered out")
lgr.Debug().Msg("Logging level raised all the way down to Trace level, Debug is higher than Trace, this will log")
Output: {"level":"debug","severity":"DEBUG","message":"This is a log at the Debug level"} {"level":"error","severity":"ERROR","message":"This is a log at the Error level"} {"level":"debug","severity":"DEBUG","message":"Logging level raised all the way down to Trace level, Debug is higher than Trace, this will log"}
func WriteErrorStack ¶
func WriteErrorStack(writeStack bool)
WriteErrorStack is a convenience function to set the zerolog ErrorStackMarshaler global variable. If true, writes error stacks for logs. If false, will turn off error stack.
Types ¶
type GCPSeverityHook ¶
type GCPSeverityHook struct{}
The GCPSeverityHook struct satisfies the zerolog.Hook interface as it has the Run method defined with the appropriate parameters