Documentation ¶
Overview ¶
Package genericr implements github.com/go-logr/logr.LogSink in a generic way that allows easy implementation of other logging backends.
Index ¶
- func NewForTesting(t TLogSink) logr.Logger
- type Entry
- type LogFunc
- type LogSink
- func (l LogSink) Enabled(level int) bool
- func (l LogSink) Error(err error, msg string, kvList ...interface{})
- func (l LogSink) Info(level int, msg string, kvList ...interface{})
- func (l LogSink) Init(info logr.RuntimeInfo)
- func (l LogSink) WithCaller(enabled bool) LogSink
- func (l LogSink) WithCallerDepth(depth int) LogSink
- func (l LogSink) WithName(name string) logr.LogSink
- func (l LogSink) WithValues(kvList ...interface{}) logr.LogSink
- func (l LogSink) WithVerbosity(level int) LogSink
- type TLogSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewForTesting ¶
NewForTesting returns a LogSink for given testing.T or B. Note that the source line reference will be incorrect in all messages written by testing.T. There is nothing we can do about that, the call depth is hardcoded in there.
Types ¶
type Entry ¶
type Entry struct { Level int // level at which this was logged Name string // name parts joined with '.' NameParts []string // individual name segments Message string // message as send to log call Error error // error if .Error() was called Fields []interface{} // alternating key-value pairs // Caller information Caller runtime.Frame // only available after .WithCaller(true) CallerDepth int // caller depth from callback }
Entry is a log entry that your adapter will receive for actual logging
func (Entry) CallerShort ¶
CallerShort returns a short caller location string ("somefile.go:123")
type LogSink ¶
type LogSink struct {
// contains filtered or unexported fields
}
LogSink is a generic logger that implements the logr.LogSink interface and calls a function of type LogFunc for every log message received.
func (LogSink) Init ¶
func (l LogSink) Init(info logr.RuntimeInfo)
func (LogSink) WithCaller ¶
WithCaller enables or disables caller lookup for Entry.Caller. It is disabled by default. Local benchmarks show close to 1µs and 2 allocs extra overhead from enabling this, without actually using this extra information. This is not part of the logr interface, so you can only use this on the root object.
func (LogSink) WithCallerDepth ¶
WithCallerDepth adjusts the caller depth. This is useful is the caller uses a custom wrapper to log messages with extra info. To actually do caller lookups, those have to be enabled with .WithCaller(true). This is not part of the logr interface, so you can only use this on the root object.
func (LogSink) WithValues ¶
func (LogSink) WithVerbosity ¶
WithVerbosity returns a new instance with given max verbosity level. This is not part of the logr interface, so you can only use this on the root object.