Documentation
¶
Overview ¶
Package logger provides a small, leveled, structured logging interface for the proxy along with a zerolog-backed implementation and a no-op implementation for tests.
Package-level functions (Debug, Info, Warn, Error, Fatal, With) delegate to a default Logger that writes to os.Stderr at LevelInfo.
Index ¶
- func Debug(msg string, tags ...tag.Tag)
- func Error(msg string, tags ...tag.Tag)
- func Fatal(msg string, tags ...tag.Tag)
- func Info(msg string, tags ...tag.Tag)
- func SetDefault(l Logger)
- func Warn(msg string, tags ...tag.Tag)
- type Level
- type Logger
- type NoopLogger
- type TestLogger
- func (t *TestLogger) Contains(msg string) bool
- func (t *TestLogger) ContainsEntry(l Level, msg string, tags ...tag.Tag) bool
- func (t *TestLogger) Debug(msg string, tags ...tag.Tag)
- func (t *TestLogger) Error(msg string, tags ...tag.Tag)
- func (t *TestLogger) Fatal(msg string, tags ...tag.Tag)
- func (t *TestLogger) Info(msg string, tags ...tag.Tag)
- func (t *TestLogger) Warn(msg string, tags ...tag.Tag)
- func (t *TestLogger) With(tags ...tag.Tag) Logger
- type ZeroLogger
- func (l *ZeroLogger) Debug(msg string, tags ...tag.Tag)
- func (l *ZeroLogger) Error(msg string, tags ...tag.Tag)
- func (l *ZeroLogger) Fatal(msg string, tags ...tag.Tag)
- func (l *ZeroLogger) Info(msg string, tags ...tag.Tag)
- func (l *ZeroLogger) Warn(msg string, tags ...tag.Tag)
- func (l *ZeroLogger) With(tags ...tag.Tag) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
Debug logs msg and tags at LevelDebug using the default logger.
func Error ¶
Error logs msg and tags at LevelError using the default logger.
func Fatal ¶
Fatal logs msg and tags using the default logger. Depending on the implementation, it may call os.Exit(1).
func SetDefault ¶
func SetDefault(l Logger)
SetDefault replaces the Logger used by the package-level functions. A nil logger is ignored. It is not safe to call concurrently with the package-level logging functions.
Types ¶
type Logger ¶
type Logger interface {
// Debug logs msg and tags at [LevelDebug].
Debug(msg string, tags ...tag.Tag)
// Error logs msg and tags at [LevelError].
Error(msg string, tags ...tag.Tag)
// Fatal logs msg and tags, then typically calls os.Exit(1).
Fatal(msg string, tags ...tag.Tag)
// Info logs msg and tags at [LevelInfo].
Info(msg string, tags ...tag.Tag)
// Warn logs msg and tags at [LevelWarn].
Warn(msg string, tags ...tag.Tag)
// With returns a child Logger that includes tags on every entry.
With(tags ...tag.Tag) Logger
}
Logger emits leveled, structured log entries. Each method takes a human readable message and zero or more tag.Tag key/value pairs.
type NoopLogger ¶
type NoopLogger struct{}
NoopLogger is a Logger that discards every entry. It is useful in tests and anywhere a non-nil Logger is required but output is not wanted. Unlike other implementations, its Fatal does not exit the process.
type TestLogger ¶
type TestLogger struct {
// contains filtered or unexported fields
}
TestLogger is a Logger that records every entry in memory so tests can assert on what was logged. It is safe for concurrent use.
Loggers derived via TestLogger.With share the recording store of the logger they were derived from, so entries logged through a derived logger are visible from the original.
A TestLogger must be created with NewTestLogger; the zero value is not usable.
func (*TestLogger) Contains ¶
func (t *TestLogger) Contains(msg string) bool
Contains reports whether an entry with the given message was logged, regardless of its level or tags.
func (*TestLogger) ContainsEntry ¶
ContainsEntry reports whether an entry was logged with exactly the given level, message, and tags. Tags must match in order, and their values are compared by equality, so tag values must be comparable.
type ZeroLogger ¶
type ZeroLogger struct {
// contains filtered or unexported fields
}
ZeroLogger is a Logger backed by zerolog. It writes structured, leveled JSON log entries, each stamped with a timestamp.
func NewZeroLogger ¶
func NewZeroLogger(w io.Writer, lvl Level) *ZeroLogger
NewZeroLogger returns a ZeroLogger that writes to w and discards any entry below lvl.