Documentation
¶
Index ¶
Constants ¶
const RequestIDHeader = "opc-request-id"
RequestIDHeader is the header to look for the request ID.
const RequestIDKey = "request-id"
RequestIDKey is the key for the request ID in the context.
const RequestLoggerKey = "request-logger"
RequestLoggerKey is the key for the logger in the context.
Variables ¶
var ConfigKey = "logging"
ConfigKey is the root configuration key (in Viper) for this module.
Module will load the configuration from Viper and creates a new logger using "logging" viper configuration key.
var TimeFormat = time.RFC3339
TimeFormat is the time format to be used when writing logs.
var TimeNowFunc = time.Now
TimeNowFunc lets you specify the function for obtaining the current time. This is mainly to aid in testing.
var UseLoggingInterface fx.Option = fx.WithLogger( func(logger Interface) fxevent.Logger { return &fxLoggerAdapter{Interface: logger} }, )
UseLoggingInterface makes fx itself log its events to the instance of logging.Interface inside the container being built. Requires logging.Interface to be provided within the resulting fx.App.
Functions ¶
func ModuleNamed ¶
ModuleNamed represents a module for *zap.Logger & logging.Interface that's loaded and annotated using a given configKey.
See https://uber-go.github.io/fx/get-started/another-handler.html and https://uber-go.github.io/fx/annotate.html#annotating-a-function.
Types ¶
type Config ¶
type Config struct { // Debug sets the logging level to debug. // // If debug is true, any value in `level` is ignored and // it forces the logger to use Console encoder (instead of JSON). // // If you want to use JSON decoder while producing debug logs, use "debug=false, level=debug" combination. // // This field is here for legacy reasons only, maybe at some point we'll be able to get rid of it. Debug bool `mapstructure:"debug"` // Level controls the logging level. // // Defaults to INFO if not set. Level Level `mapstructure:"level"` // If set, timestamps will be serialized as RFC3339Nano time format. // Otherwise, default EncodeTime formatter will be used (ISO8601 if debug is set, Epoch otherwise). // // See getZapEncoderConfig() for details. EncodeTimeAsRFC3339Nano bool `mapstructure:"encodeTimeAsRFC3339Nano"` // DisableConsoleOutput disables logs to be written to the console. // This will prevent ODO from copying these logs into journalctl -> syslog -> /var/log/user.log // which can cause disk space usage issues. DisableConsoleOutput bool `mapstructure:"disableConsoleOutput"` // Logger contains various knobs of lumberjack logging functionality. lumberjack.Logger `mapstructure:",squash"` }
Config holds the configuration for logging.
type Interface ¶
type Interface interface { WithField(key string, value interface{}) Interface WithError(err error) Interface Debug(msg string) Info(msg string) Warn(msg string) Error(msg string) Fatal(msg string) // Avoid using Printf-like methods Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) }
Interface exists solely in order to decouple clients from various implementations of logging libraries (while we transition from logrus to zap).
NOTE: This is temporary and not intended to be fast (printf-like methods are really bad). Use zap logger directly for new code (see benchmarks at https://github.com/uber-go/zap).
func Discard ¶
func Discard() Interface
Discard constructs a logger that discards any logging message.
Used as a null-object pattern.
func NewTestLogger ¶
func NewTestLogger() Interface
type Option ¶
Option is a configuration option for logging.
func WithViper ¶
WithViper applies the configuration using Viper root configuration key "logging". It assumes that Viper has already been configured to read from a config file, the environment, or flags.
By its nature, calling WithViper ensures the resulting config will never fail Validate.
func WithViperKey ¶
WithViperKey applies the configuration using Viper using a specified configuration key. It assumes that Viper has already been configured to read from a config file, the environment, or flags.
By its nature, calling WithViperKey ensures the resulting config will never fail Validate.