-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
add skipPackageNameForCaller #898
Changes from 1 commit
00967a5
fd13311
9d6c067
07bacc2
011ac2c
3b20986
e8ba338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ var ( | |
bufferPool *sync.Pool | ||
|
||
// qualified package name, cached at first use | ||
logrusPackage string | ||
skipPackageNameForCaller = make(map[string]bool, 1) | ||
|
||
// Positions in the call stack when tracing to report the calling method | ||
minimumCallerDepth int | ||
|
@@ -40,6 +40,11 @@ func init() { | |
minimumCallerDepth = 1 | ||
} | ||
|
||
// Set the global qualified package name. | ||
func SetSkipPackageNameForCaller(name string) { | ||
tossp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
skipPackageNameForCaller[name] = true | ||
} | ||
|
||
// Defines the key when adding errors using WithError. | ||
var ErrorKey = "error" | ||
|
||
|
@@ -163,18 +168,21 @@ func getCaller() *runtime.Frame { | |
|
||
// cache this package's fully-qualified name | ||
callerInitOnce.Do(func() { | ||
logrusPackage = getPackageName(runtime.FuncForPC(pcs[0]).Name()) | ||
|
||
// now that we have the cache, we can skip a minimum count of known-logrus functions | ||
// XXX this is dubious, the number of frames may vary store an entry in a logger interface | ||
minimumCallerDepth = knownLogrusFrames | ||
if len(skipPackageNameForCaller) != 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what is going on here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
minimumCallerDepth = knownLogrusFrames + 1 | ||
} else { | ||
minimumCallerDepth = knownLogrusFrames | ||
} | ||
skipPackageNameForCaller[getPackageName(runtime.FuncForPC(pcs[0]).Name())] = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I鈥檇 prefer having a local |
||
}) | ||
|
||
for f, again := frames.Next(); again; f, again = frames.Next() { | ||
pkg := getPackageName(f.Function) | ||
|
||
// If the caller isn't part of this package, we're done | ||
if pkg != logrusPackage { | ||
if !skipPackageNameForCaller[pkg] { | ||
return &f | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the examples here as well.