Skip to content

Commit afc42fb

Browse files
authored
Merge pull request #165 from linuxboot/bugfix/logging_file
fix(logging): Do not report 'logger.go' as the logging file
2 parents b12c692 + 460569f commit afc42fb

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)