Documentation ¶
Index ¶
- Constants
- Variables
- func InitGlobalLogger(config *configuration.Configuration) error
- func NewEventCore(enabler zapcore.LevelEnabler) zapcore.Core
- func SetLevel(l Level)
- type Config
- type EventsStruct
- type Level
- type LogEvent
- type Logger
- func NewExampleLogger(name string) *Logger
- func NewLogger(name string) *Logger
- func NewNopLogger() *Logger
- func NewRootLogger(cfg Config, levelOverride ...zap.AtomicLevel) (*Logger, error)
- func NewRootLoggerFromConfiguration(config *configuration.Configuration, levelOverride ...zap.AtomicLevel) (*Logger, error)
- type WrappedLogger
- func (l *WrappedLogger) LogDebug(args ...interface{})
- func (l *WrappedLogger) LogDebugf(template string, args ...interface{})
- func (l *WrappedLogger) LogError(args ...interface{})
- func (l *WrappedLogger) LogErrorAndExit(args ...interface{})
- func (l *WrappedLogger) LogErrorf(template string, args ...interface{})
- func (l *WrappedLogger) LogErrorfAndExit(template string, args ...interface{})
- func (l *WrappedLogger) LogFatalAndExit(args ...interface{})
- func (l *WrappedLogger) LogFatalfAndExit(template string, args ...interface{})
- func (l *WrappedLogger) LogInfo(args ...interface{})
- func (l *WrappedLogger) LogInfof(template string, args ...interface{})
- func (l *WrappedLogger) LogPanic(args ...interface{})
- func (l *WrappedLogger) LogPanicf(template string, args ...interface{})
- func (l *WrappedLogger) LogWarn(args ...interface{})
- func (l *WrappedLogger) LogWarnf(template string, args ...interface{})
- func (l *WrappedLogger) Logger() *Logger
- func (l *WrappedLogger) LoggerNamed(name string) *Logger
Constants ¶
const ( ConfigurationKeyLevel = "logger.level" ConfigurationKeyDisableCaller = "logger.disableCaller" ConfigurationKeyDisableStacktrace = "logger.disableStacktrace" ConfigurationKeyStacktraceLevel = "logger.stacktraceLevel" ConfigurationKeyEncoding = "logger.encoding" ConfigurationKeyOutputPaths = "logger.outputPaths" ConfigurationKeyDisableEvents = "logger.disableEvents" )
const ( // LevelDebug logs are typically voluminous, and are usually disabled in production. LevelDebug = zapcore.DebugLevel // LevelInfo is the default logging priority. LevelInfo = zapcore.InfoLevel // LevelWarn logs are more important than Info, but don't need individual human review. LevelWarn = zapcore.WarnLevel // LevelError logs are high-priority. // If an application is running as expected, there shouldn't be any error-level logs. LevelError = zapcore.ErrorLevel // LevelPanic logs a message, then panics. LevelPanic = zapcore.PanicLevel // LevelFatal logs a message, then calls os.Exit(1). LevelFatal = zapcore.FatalLevel )
Variables ¶
var ErrGlobalLoggerAlreadyInitialized = errors.New("global logger already initialized")
ErrGlobalLoggerAlreadyInitialized is returned when InitGlobalLogger is called more than once.
Functions ¶
func InitGlobalLogger ¶
func InitGlobalLogger(config *configuration.Configuration) error
InitGlobalLogger initializes the global logger from the provided config.
func NewEventCore ¶
func NewEventCore(enabler zapcore.LevelEnabler) zapcore.Core
NewEventCore creates a core that publishes log messages as events.
Types ¶
type Config ¶
type Config struct { // Level is the minimum enabled logging level. // The default is "info". Level string `default:"info" usage:"the minimum enabled logging level" json:"level"` // DisableCaller stops annotating logs with the calling function's file name and line number. // By default, logs are not annotated. DisableCaller bool `default:"true" usage:"stops annotating logs with the calling function's file name and line number" json:"disableCaller"` // DisableStacktrace disables automatic stacktrace capturing. DisableStacktrace bool `default:"false" usage:"disables automatic stacktrace capturing" json:"disableStacktrace"` // StacktraceLevel is the level stacktraces are captured and above. // The default is "panic". StacktraceLevel string `default:"panic" usage:"the level stacktraces are captured and above" json:"stacktraceLevel"` // Encoding sets the logger's encoding. Valid values are "json" and "console". // The default is "console". Encoding string `default:"console" usage:"the logger's encoding (options: \"json\", \"console\")" json:"encoding"` // OutputPaths is a list of URLs, file paths or stdout/stderr to write logging output to. // The default is ["stdout"]. OutputPaths []string `default:"stdout" usage:"a list of URLs, file paths or stdout/stderr to write logging output to" json:"outputPaths"` // DisableEvents prevents log messages from being raced as events. // By default, the corresponding events are not triggered. DisableEvents bool `default:"true" usage:"prevents log messages from being raced as events" json:"disableEvents"` }
Config holds the settings to configure a root logger instance.
type EventsStruct ¶
type EventsStruct struct { DebugMsg *event.Event[*LogEvent] InfoMsg *event.Event[*LogEvent] WarningMsg *event.Event[*LogEvent] ErrorMsg *event.Event[*LogEvent] PanicMsg *event.Event[*LogEvent] AnyMsg *event.Event[*LogEvent] }
EventsStruct contains all the events that are triggered by the logger.
var Events *EventsStruct
type Logger ¶
type Logger = zap.SugaredLogger
The Logger uses the sugared logger.
func NewExampleLogger ¶
NewExampleLogger builds a Logger that's designed to be only used in tests or examples. It writes debug and above logs to standard out as JSON, but omits the timestamp and calling function to keep example output short and deterministic.
func NewNopLogger ¶
func NewNopLogger() *Logger
NewNopLogger returns a no-op Logger. It never writes out logs or internal errors.
func NewRootLogger ¶
func NewRootLogger(cfg Config, levelOverride ...zap.AtomicLevel) (*Logger, error)
NewRootLogger creates a new root logger from the provided configuration.
func NewRootLoggerFromConfiguration ¶
func NewRootLoggerFromConfiguration(config *configuration.Configuration, levelOverride ...zap.AtomicLevel) (*Logger, error)
NewRootLoggerFromConfiguration creates a new root logger from the provided configuration.
type WrappedLogger ¶
type WrappedLogger struct {
// contains filtered or unexported fields
}
WrappedLogger is a wrapper to call logging functions in case a logger was passed.
func NewWrappedLogger ¶
func NewWrappedLogger(logger *Logger) *WrappedLogger
NewWrappedLogger creates a new WrappedLogger.
func (*WrappedLogger) LogDebug ¶
func (l *WrappedLogger) LogDebug(args ...interface{})
LogDebug uses fmt.Sprint to construct and log a message.
func (*WrappedLogger) LogDebugf ¶
func (l *WrappedLogger) LogDebugf(template string, args ...interface{})
LogDebugf uses fmt.Sprintf to log a templated message.
func (*WrappedLogger) LogError ¶
func (l *WrappedLogger) LogError(args ...interface{})
LogError uses fmt.Sprint to construct and log a message.
func (*WrappedLogger) LogErrorAndExit ¶
func (l *WrappedLogger) LogErrorAndExit(args ...interface{})
LogErrorAndExit uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*WrappedLogger) LogErrorf ¶
func (l *WrappedLogger) LogErrorf(template string, args ...interface{})
LogErrorf uses fmt.Sprintf to log a templated message.
func (*WrappedLogger) LogErrorfAndExit ¶
func (l *WrappedLogger) LogErrorfAndExit(template string, args ...interface{})
LogErrorfAndExit uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (*WrappedLogger) LogFatalAndExit ¶
func (l *WrappedLogger) LogFatalAndExit(args ...interface{})
LogFatalAndExit uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (*WrappedLogger) LogFatalfAndExit ¶
func (l *WrappedLogger) LogFatalfAndExit(template string, args ...interface{})
LogFatalfAndExit uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (*WrappedLogger) LogInfo ¶
func (l *WrappedLogger) LogInfo(args ...interface{})
LogInfo uses fmt.Sprint to construct and log a message.
func (*WrappedLogger) LogInfof ¶
func (l *WrappedLogger) LogInfof(template string, args ...interface{})
LogInfof uses fmt.Sprintf to log a templated message.
func (*WrappedLogger) LogPanic ¶
func (l *WrappedLogger) LogPanic(args ...interface{})
LogPanic uses fmt.Sprint to construct and log a message, then panics.
func (*WrappedLogger) LogPanicf ¶
func (l *WrappedLogger) LogPanicf(template string, args ...interface{})
LogPanicf uses fmt.Sprintf to log a templated message, then panics.
func (*WrappedLogger) LogWarn ¶
func (l *WrappedLogger) LogWarn(args ...interface{})
LogWarn uses fmt.Sprint to construct and log a message.
func (*WrappedLogger) LogWarnf ¶
func (l *WrappedLogger) LogWarnf(template string, args ...interface{})
LogWarnf uses fmt.Sprintf to log a templated message.
func (*WrappedLogger) Logger ¶
func (l *WrappedLogger) Logger() *Logger
Logger return the underlying logger.
func (*WrappedLogger) LoggerNamed ¶
func (l *WrappedLogger) LoggerNamed(name string) *Logger
LoggerNamed adds a sub-scope to the logger's name. See Logger.Named for details.