Documentation ¶
Overview ¶
Package logger is a helper package for logging
Index ¶
- Constants
- func DPanic(config *zap.Config)
- func Debug(config *zap.Config)
- func DisableCaller(config *zap.Config)
- func DisableStacktrace(config *zap.Config)
- func Error(config *zap.Config)
- func Fatal(config *zap.Config)
- func Info(config *zap.Config)
- func ObserverForTest() *observer.ObservedLogs
- func Panic(config *zap.Config)
- func Replace(logger *Logger)
- func Setup(env environment.Environment) error
- func Warn(config *zap.Config)
- func WithConsoleEncoding(config *zap.Config)
- func WithGoogleEncoding(cfg *zap.Config)
- type Logger
- func (l *Logger) AddCommon(fields ...zap.Field)
- func (l *Logger) Clone() *Logger
- func (l *Logger) DPanic(msg string, fields ...zap.Field)
- func (l *Logger) Debug(msg string, fields ...zap.Field)
- func (l *Logger) Error(msg string, fields ...zap.Field)
- func (l *Logger) ErrorIf(err error, msg string, fields ...zap.Field)
- func (l *Logger) Fatal(msg string, fields ...zap.Field)
- func (l *Logger) FatalIf(err error, msg string, fields ...zap.Field)
- func (l *Logger) Info(msg string, fields ...zap.Field)
- func (l *Logger) Panic(msg string, fields ...zap.Field)
- func (l *Logger) Sync()
- func (l *Logger) TimedLog(tl *TimedLog)
- func (l *Logger) Warn(msg string, fields ...zap.Field)
- type Option
- type TimedLog
- type TimedLogConfig
Constants ¶
const ( // BinaryDebugLogging is the environment variable that can be used to enable debug logging in a binary BinaryDebugLogging environment.Name = "PACKAGED__DEBUG_LOG" )
Variables ¶
This section is empty.
Functions ¶
func DisableCaller ¶
DisableCaller disables the caller in the log output
func DisableStacktrace ¶
DisableStacktrace disabled stack traces in the log output
func ObserverForTest ¶
func ObserverForTest() *observer.ObservedLogs
ObserverForTest returns an observer for the global logger instance if it exists
func WithConsoleEncoding ¶
WithConsoleEncoding sets the encoding to console
func WithGoogleEncoding ¶
WithGoogleEncoding sets the encoding to google cloud logging format
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a wrapper around zap.Logger
func InstanceWithConfig ¶
func InstanceWithConfig(env environment.Environment, cfg zap.Config, options ...Option) (*Logger, error)
InstanceWithConfig creates a new logger instance with the provided config & options applied
func (*Logger) DPanic ¶
DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.
func (*Logger) Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func (*Logger) Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func (*Logger) Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
type TimedLog ¶ added in v3.1.0
type TimedLog struct {
// contains filtered or unexported fields
}
func NewTimedLog ¶ added in v3.1.0
func NewTimedLog(cnf *TimedLogConfig, message string, fields ...zap.Field) *TimedLog
type TimedLogConfig ¶ added in v3.1.0
type TimedLogConfig struct { ErrorDuration time.Duration WarnDuration time.Duration InfoDuration time.Duration DebugDuration time.Duration }
func DefaultTimedLogConfig ¶ added in v3.1.0
func DefaultTimedLogConfig() *TimedLogConfig