Documentation
¶
Index ¶
- Constants
- func ContextWithLogger(ctx context.Context, logger *Logger) context.Context
- type Format
- type Level
- type Logger
- func (l *Logger) Debug(msg string, keysAndValues ...any)
- func (l *Logger) Error(err error, msg string, keysAndValues ...any)
- func (l *Logger) Info(msg string, keysAndValues ...any)
- func (l *Logger) Logr() logr.Logger
- func (l *Logger) Trace(msg string, keysAndValues ...any)
- func (l *Logger) WithValues(keysAndValues ...any) *Logger
- func (l *Logger) WithoutStackTraces() *Logger
Constants ¶
const ( // Note(krancour): Numerically speaking, zap supports levels above or below // those for it has defined constants. This is how we implement our own // Discard and Trace levels. DiscardLevel Level = Level(zapcore.FatalLevel + 1) ErrorLevel Level = Level(zapcore.ErrorLevel) InfoLevel Level = Level(zapcore.InfoLevel) DebugLevel Level = Level(zapcore.DebugLevel) TraceLevel Level = DebugLevel - 1 ConsoleFormat Format = "console" JSONFormat Format = "json" DefaultFormat Format = ConsoleFormat LogLevelEnvVar = "LOG_LEVEL" LogFormatEnvVar = "LOG_FORMAT" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Format ¶
type Format string
func ParseFormat ¶
ParseFormat parses a string representation of a log format and returns the corresponding Format value or an error if it isn't recognized
type Level ¶
type Level int8
func ParseLevel ¶
ParseLevel parses a string representation of a log level and returns the corresponding Level value.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a simple wrapper around zap.Logger that provides a more ergonomic API.
func LoggerFromContext ¶
LoggerFromContext extracts a *Logger from the provided context.Context and returns it. If no *Logger is found, a global *Logger is returned.
func NewDiscardLoggerOrDie ¶ added in v1.8.8
func NewDiscardLoggerOrDie() *Logger
NewDiscardLoggerOrDie returns a new *Logger that discards all log output or panics if there is an error configuring the logger. This is primarily useful for tests.
func NewLoggerOrDie ¶
NewLoggerOrDie returns a new *Logger with the provided log level or panics if there is an error configuring the logger.
func (*Logger) Logr ¶ added in v1.8.8
Logr returns a logr.Logger wrapped in this Logger's underlying zap.Logger for cases where one needs to to pass the a logr.Logger to another library that obviously doesn't know how to work with our custom one.
func (*Logger) WithValues ¶
WithValues adds key-value pairs to a logger's context.
func (*Logger) WithoutStackTraces ¶ added in v1.12.0
WithoutStackTraces returns a copy of a logger that does not attach a stack trace to the records it writes. A stack trace describes the path to the logging call, not the path to whatever went wrong, so it is worth having only where an error is logged near where it arose. Callers that log errors on behalf of code far below them should use this.