Documentation ¶
Overview ¶
Package logr contains utilities for fetching a new logger when one is not already available.
The Log Handle ¶
This package contains a root logr.Logger Log. It may be used to get a handle to whatever the root logging implementation is. By default, no implementation exists, and the handle returns "promises" to loggers. When the implementation is set using SetLogger, these "promises" will be converted over to real loggers.
Logr ¶
All logging in Gate is structured, using a set of interfaces defined by a package called logr (https://pkg.go.dev/github.com/go-logr/logr). The sub-package zap provides helpers for setting up logr backed by Zap (go.uber.org/zap).
Index ¶
- func IntoContext(ctx context.Context, log Logger) context.Context
- func SetLogger(l Logger)
- type DelegatingLogSink
- func (l *DelegatingLogSink) Enabled(level int) bool
- func (l *DelegatingLogSink) Error(err error, msg string, keysAndValues ...interface{})
- func (l *DelegatingLogSink) Fulfill(actual logr.LogSink)
- func (l *DelegatingLogSink) Info(level int, msg string, keysAndValues ...interface{})
- func (l *DelegatingLogSink) Init(info logr.RuntimeInfo)
- func (l *DelegatingLogSink) WithName(name string) logr.LogSink
- func (l *DelegatingLogSink) WithValues(tags ...interface{}) logr.LogSink
- type Logger
- type NullLogSink
- func (NullLogSink) Enabled(level int) bool
- func (NullLogSink) Error(_ error, _ string, _ ...interface{})
- func (NullLogSink) Info(_ int, _ string, _ ...interface{})
- func (log NullLogSink) Init(logr.RuntimeInfo)
- func (log NullLogSink) WithName(_ string) logr.LogSink
- func (log NullLogSink) WithValues(_ ...interface{}) logr.LogSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IntoContext ¶ added in v0.18.0
IntoContext takes a context and sets the logger as one of its values. Use FromContext function to retrieve the logger.
Types ¶
type DelegatingLogSink ¶ added in v0.18.0
type DelegatingLogSink struct {
// contains filtered or unexported fields
}
DelegatingLogSink is a logsink that delegates to another logr.LogSink. If the underlying promise is not nil, it registers calls to sub-loggers with the logging factory to be populated later, and returns a new delegating logger. It expects to have *some* logr.Logger set at all times (generally a no-op logger before the promises are fulfilled).
func NewDelegatingLogSink ¶ added in v0.18.0
func NewDelegatingLogSink(initial logr.LogSink) *DelegatingLogSink
NewDelegatingLogSink constructs a new DelegatingLogSink which uses the given logger before its promise is fulfilled.
func (*DelegatingLogSink) Enabled ¶ added in v0.18.0
func (l *DelegatingLogSink) Enabled(level int) bool
Enabled tests whether this Logger is enabled. For example, commandline flags might be used to set the logging verbosity and disable some info logs.
func (*DelegatingLogSink) Error ¶ added in v0.18.0
func (l *DelegatingLogSink) Error(err error, msg string, keysAndValues ...interface{})
Error logs an error, with the given message and key/value pairs as context. It functions similarly to calling Info with the "error" named value, but may have unique behavior, and should be preferred for logging errors (see the package documentations for more information).
The msg field should be used to add context to any underlying error, while the err field should be used to attach the actual error that triggered this log line, if present.
func (*DelegatingLogSink) Fulfill ¶ added in v0.18.0
func (l *DelegatingLogSink) Fulfill(actual logr.LogSink)
Fulfill switches the logger over to use the actual logger provided, instead of the temporary initial one, if this method has not been previously called.
func (*DelegatingLogSink) Info ¶ added in v0.18.0
func (l *DelegatingLogSink) Info(level int, msg string, keysAndValues ...interface{})
Info logs a non-error message with the given key/value pairs as context.
The msg argument should be used to add some constant description to the log line. The key/value pairs can then be used to add additional variable information. The key/value pairs should alternate string keys and arbitrary values.
func (*DelegatingLogSink) Init ¶ added in v0.18.0
func (l *DelegatingLogSink) Init(info logr.RuntimeInfo)
Init implements logr.LogSink.
func (*DelegatingLogSink) WithName ¶ added in v0.18.0
func (l *DelegatingLogSink) WithName(name string) logr.LogSink
WithName provides a new Logger with the name appended.
func (*DelegatingLogSink) WithValues ¶ added in v0.18.0
func (l *DelegatingLogSink) WithValues(tags ...interface{}) logr.LogSink
WithValues provides a new Logger with the tags appended.
type Logger ¶
Logger is Gate's logger interface.
Log is the base logger used by Gate. It delegates to another logr.Logger. You *must* call SetLogger to get any actual logging. If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get set to a NullLogSink.
var NopLog Logger = logr.New(NullLogSink{})
NopLog is a Logger that does nothing.
func FromContext ¶ added in v0.18.0
FromContext returns a logger with predefined values from a context.Context.
type NullLogSink ¶ added in v0.18.0
type NullLogSink struct{}
NullLogSink is a logr.Logger that does nothing.
func (NullLogSink) Enabled ¶ added in v0.18.0
func (NullLogSink) Enabled(level int) bool
Enabled implements logr.InfoLogger.
func (NullLogSink) Error ¶ added in v0.18.0
func (NullLogSink) Error(_ error, _ string, _ ...interface{})
Error implements logr.Logger.
func (NullLogSink) Info ¶ added in v0.18.0
func (NullLogSink) Info(_ int, _ string, _ ...interface{})
Info implements logr.InfoLogger.
func (NullLogSink) Init ¶ added in v0.18.0
func (log NullLogSink) Init(logr.RuntimeInfo)
Init implements logr.LogSink.
func (NullLogSink) WithName ¶ added in v0.18.0
func (log NullLogSink) WithName(_ string) logr.LogSink
WithName implements logr.Logger.
func (NullLogSink) WithValues ¶ added in v0.18.0
func (log NullLogSink) WithValues(_ ...interface{}) logr.LogSink
WithValues implements logr.Logger.