Documentation ¶
Overview ¶
Package logutils implements helpers for logging.
Index ¶
- Variables
- func ContextWithZap(parent context.Context, logger *zap.Logger) context.Context
- func FlushZap(logger *zap.Logger)
- func GetZapLogger(options ...LogConfigOption) (*zap.Logger, error)
- func MustGetZapLogger(options ...LogConfigOption) *zap.Logger
- func RequestWithZap(parent *http.Request, logger *zap.Logger) *http.Request
- func ZapFromContext(ctx context.Context) *zap.Logger
- func ZapFromRequest(request *http.Request) *zap.Logger
- type LogConfigOption
Constants ¶
This section is empty.
Variables ¶
var Levels = []string{ zap.DebugLevel.String(), zap.InfoLevel.String(), zap.WarnLevel.String(), zap.ErrorLevel.String(), zap.DPanicLevel.String(), zap.PanicLevel.String(), zap.FatalLevel.String(), }
Functions ¶
func ContextWithZap ¶
ContextWithZap returns a copy of parent context injected with corresponding zap logger.
func FlushZap ¶
FlushZap triggers the Sync() on the logger. In case of an error, it will log it using the logger from standard library.
func GetZapLogger ¶
func GetZapLogger(options ...LogConfigOption) (*zap.Logger, error)
GetZapLogger returns a logger created according to the provided options. In case if anything goes wrong (for example if the log-level string can not be parsed) it will return a logger (with configuration that is closest possible to the desired one) and an error.
func MustGetZapLogger ¶
func MustGetZapLogger(options ...LogConfigOption) *zap.Logger
MustGetZapLogger is guaranteed to return a logger with configuration as close as possible to the desired one. Any errors encountered in the process will be logged as warnings with the resulting logger.
func RequestWithZap ¶
RequestWithZap returns a shallow copy of parent request with context being supplemented with corresponding zap logger.
func ZapFromContext ¶
ZapFromContext retrieves the zap logger passed with a context.
Types ¶
type LogConfigOption ¶
type LogConfigOption = func(*loggerConfig)
LogConfigOption allows to fine-tune the configuration of the logger.
func LogDevMode ¶
func LogDevMode(devMode bool) LogConfigOption
LogDevMode tells the logger to work in the development mode.
func LogLevel ¶
func LogLevel(level string) LogConfigOption
LogLevel sets the desired level of logging.