From f3b316d4d4d272777aea9ef016c2c1d1a24a186a Mon Sep 17 00:00:00 2001 From: Simon Sawert Date: Mon, 21 Aug 2023 21:34:53 +0200 Subject: [PATCH] Make WithCallDepth additive Resolves #27 --- logrusr.go | 2 +- logrusr_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/logrusr.go b/logrusr.go index 91cdd5f..c0ded86 100644 --- a/logrusr.go +++ b/logrusr.go @@ -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 } diff --git a/logrusr_test.go b/logrusr_test.go index 5645ffc..d52e8fd 100644 --- a/logrusr_test.go +++ b/logrusr_test.go @@ -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 {