Skip to content

Commit

Permalink
Merge pull request sirupsen#1102 from hlcfan/get-right-logrus-pkg-name
Browse files Browse the repository at this point in the history
Fix caller package name
  • Loading branch information
dgsb committed Mar 6, 2020
2 parents b924f6f + 284cce4 commit 6f5e581
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion entry.go
Expand Up @@ -185,7 +185,7 @@ func getCaller() *runtime.Frame {
callerInitOnce.Do(func() {
pcs := make([]uintptr, 2)
_ = runtime.Callers(0, pcs)
logrusPackage = getPackageName(runtime.FuncForPC(pcs[1]).Name())
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
Expand Down
10 changes: 10 additions & 0 deletions versions_go1_14.go
@@ -0,0 +1,10 @@
// +build go1.14

package logrus

import "runtime"

// funcName returns the function name that logrus calls
func funcName(pcs []uintptr) string {
return runtime.FuncForPC(pcs[0]).Name()
}
10 changes: 10 additions & 0 deletions versions_others.go
@@ -0,0 +1,10 @@
// +build !go1.14

package logrus

import "runtime"

// funcName returns the function name that logrus calls
func funcName(pcs []uintptr) string {
return runtime.FuncForPC(pcs[1]).Name()
}

0 comments on commit 6f5e581

Please sign in to comment.