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 LogErrorStackViaPkgErrors ¶ added in v0.51.0
func LogErrorStackViaPkgErrors(p bool)
LogErrorStackViaPkgErrors is a convenience function to set the zerolog ErrorStackMarshaler global variable. If true, writes error stacks for logs using "github.com/pkg/errors". If false, will use the internal errs.Op stack instead of "github.com/pkg/errors".
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"}
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