Skip to content

Commit

Permalink
Make WithCallDepth additive
Browse files Browse the repository at this point in the history
Resolves #27
  • Loading branch information
bombsimon committed Aug 22, 2023
1 parent d198d3e commit f3b316d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion logrusr.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (l *logrusr) copyLogger() *logrusr {
// when reporting caller.
func (l *logrusr) WithCallDepth(depth int) logr.LogSink {
newLogger := l.copyLogger()
newLogger.depth = depth
newLogger.depth += depth

return newLogger
}
Expand Down
15 changes: 15 additions & 0 deletions logrusr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ func TestLogging(t *testing.T) {
"caller": `~testing.go:\d+`,
},
},
{
description: "with call depth is additive",
logFunc: func(log logr.Logger) {
log.
WithCallDepth(1).
WithCallDepth(1).
Info("hello, world")
},
reportCaller: true,
assertions: map[string]string{
"level": "info",
"msg": "hello, world",
"caller": `~testing.go:\d+`,
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit f3b316d

Please sign in to comment.