func NewForTesting(t TLogSink) logr.Logger
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.
Entry is a log entry that your adapter will receive for actual logging
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 }
func (e Entry) CallerShort() string
CallerShort returns a short caller location string ("somefile.go:123")
func (e Entry) FieldsMap() map[string]interface{}
FieldsMap converts the fields to a map. This map is also compatible with logrus.Fields.
func (e Entry) String() string
String converts the entry to a string. The output format is subject to change! Implement your own conversion if you need to parse these logs later! TODO: Neater way to log values with newlines?
LogFunc is your custom log backend
type LogFunc func(e Entry)
LogSink is a generic logger that implements the logr.LogSink interface and calls a function of type LogFunc for every log message received.
type LogSink struct {
// contains filtered or unexported fields
}
func New(f LogFunc) LogSink
New returns a logr.LogSink which is implemented by your custom LogFunc.
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) WithCallDepth(depth int) logr.LogSink
WithCallDepth implements logr.CallDepthLogSink.
func (l LogSink) WithCaller(enabled bool) LogSink
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 (l LogSink) WithName(name string) logr.LogSink
func (l LogSink) WithValues(kvList ...interface{}) logr.LogSink
func (l LogSink) WithVerbosity(level int) LogSink
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.
TLogSink is the subset of the testing.TB interface we need to log with it
type TLogSink interface { Log(args ...interface{}) }