Documentation ¶
Overview ¶
Package log exposes logging utilities based on go.uber.org/zap.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustGetLogger ¶
func MustGetLogger(name string, opts ...LoggerOption) (*zap.Logger, func())
MustGetLogger creates a named zap logger, typically to inject into a service runtime as the root logger.
This function returns a configured zap.Logger and a closing function to sync logs upon exit.
It panics upon failures, such as invalid log level, or incapacity to build the underlying logger.
Types ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory is wrapper for a logger, which creates logger instances, either contextless or for a given context (e.g. to propagate trace spans).
A factory wraps a logger to propagate log entries as trace spans.
Loggers are zap structured loggers: see go.uber.org/zap.
func GetTestLoggerConfig ¶
func GetTestLoggerConfig(opts ...LoggerOption) (Factory, *zap.Logger, error)
GetTestLoggerConfig is intended to be used in test programs, and inject a logger factory or its underlying *zap.Logger into the tested components.
It is configurable from the "DEBUG_TEST" environment variable: if set, logging is enabled. Otherwise, logging is just muted, allowing to keep test verbosity low.
func MustGetTestLoggerConfig ¶
MustGetTestLoggerConfig is a wrapper around GetTestLoggerConfig that panics if an error is encountered.
func NewFactory ¶
NewFactory creates a new logger Factory for an underlying zap logger.
func (Factory) For ¶
For returns a context-aware Logger.
If the context contains a trace span (from go.opencensus.io/trace), all logging calls are also echo-ed to that span.
NOTE: for Datadog trace correlation, extra fields "dd.trace_id" and "dd.span_id" fields are added to the log entry.
func (Factory) With ¶
With creates a child logger and optionally adds some context fields to that logger.
func (Factory) WithZapOptions ¶
WithZapOptions creates a child logger with some zap.Option
type Logger ¶
type Logger interface { Debug(msg string, fields ...zapcore.Field) Info(msg string, fields ...zapcore.Field) Warn(msg string, fields ...zapcore.Field) Error(msg string, fields ...zapcore.Field) Fatal(msg string, fields ...zapcore.Field) With(fields ...zapcore.Field) Logger Zap() *zap.Logger }
Logger is a simplified abstraction of the zap.Logger
type LoggerOption ¶
type LoggerOption func(*loggerOptions)
LoggerOption sets options to tune the behavior of a logger.
func WithCallerSkip ¶
func WithCallerSkip(skipped int) LoggerOption
WithCallerSkip sets the number of frames in the stack to skip.
By default, this is set to 1, so the logging function itself is skipped.
func WithDisableStackTrace ¶
func WithDisableStackTrace(disabled bool) LoggerOption
WithDisableStackTrace disable stack printing for this logger
func WithIgnoreErr ¶ added in v1.0.1
func WithIgnoreErr(enabled bool) LoggerOption
WithIgnoreErr ignores errors when parsing an invalid log level, and silently substitutes the default instead.
func WithLevel ¶
func WithLevel(level string) LoggerOption
WithLevel sets the log level.
The level value must parse to a valid zapcore.Level, i.e. one of error, warn, info, debug values. The default level is "info".
func WithRedirectStdLog ¶ added in v1.0.1
func WithRedirectStdLog(enabled bool) LoggerOption
func WithReplaceGlobals ¶ added in v1.0.1
func WithReplaceGlobals(enabled bool) LoggerOption