File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,14 @@ package logging
77
88import (
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+ }
You can’t perform that action at this time.
0 commit comments