Skip to content

Commit 460569f

Browse files
committed
fix(logging): Do not report 'logger.go' as the logging file
Without this fix: [2023-06-07T15:19:31.783+01:00 I logger.go:53] Registering test step sshcmd [2023-06-07T15:19:31.783+01:00 I logger.go:53] Registering reporter noop With this fix: [2023-06-07T15:12:38.611+01:00 I pluginregistry.go:91] Registering test step sshcmd [2023-06-07T15:12:38.611+01:00 I pluginregistry.go:115] Registering reporter noop Signed-off-by: Dmitrii Okunev <[email protected]>
1 parent b12c692 commit 460569f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

pkg/logging/default_options.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ package logging
77

88
import (
99
"context"
10+
stdruntime "runtime"
11+
"strings"
1012

13+
"github.com/facebookincubator/go-belt/pkg/runtime"
1114
"github.com/facebookincubator/go-belt/tool/logger"
1215
"github.com/facebookincubator/go-belt/tool/logger/implementation/logrus"
1316
"github.com/facebookincubator/go-belt/tool/logger/implementation/logrus/formatter"
17+
loggertypes "github.com/facebookincubator/go-belt/tool/logger/types"
1418
)
1519

1620
// DefaultOptions is a set options recommended to use by default.
@@ -22,6 +26,23 @@ func WithBelt(
2226
l.Formatter = &formatter.CompactText{
2327
TimestampFormat: "2006-01-02T15:04:05.000Z07:00",
2428
}
25-
ctx = logger.CtxWithLogger(ctx, logrus.New(l).WithLevel(logLevel))
29+
ctx = logger.CtxWithLogger(ctx, logrus.New(l, loggertypes.OptionGetCallerFunc(getCallerPC)).WithLevel(logLevel))
2630
return ctx
2731
}
32+
33+
func getCallerPC() runtime.PC {
34+
return runtime.Caller(func(pc uintptr) bool {
35+
if !runtime.DefaultCallerPCFilter(pc) {
36+
return false
37+
}
38+
39+
fn := stdruntime.FuncForPC(pc)
40+
funcName := fn.Name()
41+
switch {
42+
case strings.Contains(funcName, "pkg/logging"):
43+
return false
44+
}
45+
46+
return true
47+
})
48+
}

0 commit comments

Comments
 (0)