diff --git a/log/default.go b/log/default.go index e78f1e3d..c898cd6c 100644 --- a/log/default.go +++ b/log/default.go @@ -188,7 +188,11 @@ func (l *defaultLogger) Panicw(msg string, keysAndValues ...interface{}) { } func (l *defaultLogger) WithContext(_ context.Context) CommonLogger { - return l + return &defaultLogger{ + stdlog: l.stdlog, + level: l.level, + depth: l.depth - 1, + } } func (l *defaultLogger) SetLevel(level Level) { diff --git a/log/default_test.go b/log/default_test.go index 7562b0a1..9dd5fd7c 100644 --- a/log/default_test.go +++ b/log/default_test.go @@ -156,6 +156,22 @@ func Test_LogfKeyAndValues(t *testing.T) { } } +func Test_WithContextCaller(t *testing.T) { + logger = &defaultLogger{ + stdlog: log.New(os.Stderr, "", log.Lshortfile), + depth: 4, + } + + var w byteSliceWriter + SetOutput(&w) + ctx := context.TODO() + + WithContext(ctx).Info("") + Info("") + + utils.AssertEqual(t, "default_test.go:169: [Info] \ndefault_test.go:170: [Info] \n", string(w.b)) +} + func Test_SetLevel(t *testing.T) { setLogger := &defaultLogger{ stdlog: log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds),