Merge pull request #1102 from hlcfan/get-right-logrus-pkg-name

Fix caller package name
This commit is contained in:
David Bariod 2020-03-06 11:24:46 +01:00 committed by GitHub
commit 7ea96a3284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -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

10
versions_go1_14.go Normal file
View File

@ -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
versions_others.go Normal file
View File

@ -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()
}