Skip to content

Commit

Permalink
Implement call depth in new struct model
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Apr 8, 2021
1 parent 50c3949 commit 42bb35d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion funcr/funcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func New(fn func(prefix, args string), opts Options) logr.Logger {
fnl := fnlogger{
prefix: "",
values: nil,
depth: 0,
write: fn,
logCaller: opts.LogCaller,
verbosity: opts.Verbosity,
Expand Down Expand Up @@ -65,6 +66,7 @@ const (
type fnlogger struct {
prefix string
values []interface{}
depth int
write func(prefix, args string)
logCaller MessageClass
verbosity int
Expand Down Expand Up @@ -268,7 +270,7 @@ func (l fnlogger) caller() callerID {
// +1 for this frame, +1 for logr itself.
// FIXME: Maybe logr should offer a clue as to how many frames are
// needed here? Or is it part of the contract to LogSinks?
_, file, line, ok := runtime.Caller(framesToCaller() + 2)
_, file, line, ok := runtime.Caller(framesToCaller() + l.depth + 2)
if !ok {
return callerID{"<unknown>", 0}
}
Expand Down Expand Up @@ -326,4 +328,10 @@ func (l fnlogger) WithValues(kvList ...interface{}) logr.LogSink {
return l
}

func (l fnlogger) WithCallDepth(depth int) logr.LogSink {
l.depth += depth
return l
}

var _ logr.LogSink = fnlogger{}
var _ logr.CallDepthLogSink = fnlogger{}

0 comments on commit 42bb35d

Please sign in to comment.