Skip to content

Commit

Permalink
Merge pull request sirupsen#1108 from cirelli94/fix-wrong-caller
Browse files Browse the repository at this point in the history
Fix wrong caller
  • Loading branch information
markphelps committed Mar 22, 2020
2 parents 1bd0ea1 + 6b08d78 commit c60851f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
15 changes: 10 additions & 5 deletions entry.go
Expand Up @@ -180,15 +180,20 @@ func getPackageName(f string) string {

// getCaller retrieves the name of the first non-logrus calling function
func getCaller() *runtime.Frame {

// cache this package's fully-qualified name
callerInitOnce.Do(func() {
pcs := make([]uintptr, 2)
pcs := make([]uintptr, maximumCallerDepth)
_ = runtime.Callers(0, pcs)
logrusPackage = getPackageName(funcName(pcs))

// 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
// dynamic get the package name and the minimum caller depth
for i := 0; i < maximumCallerDepth; i++ {
funcName := runtime.FuncForPC(pcs[i]).Name()
if strings.Contains(funcName, "getCaller") {
logrusPackage = getPackageName(funcName)
break
}
}

minimumCallerDepth = knownLogrusFrames
})

Expand Down
10 changes: 0 additions & 10 deletions versions_go1_14.go

This file was deleted.

10 changes: 0 additions & 10 deletions versions_others.go

This file was deleted.

0 comments on commit c60851f

Please sign in to comment.