Merge pull request #1108 from cirelli94/fix-wrong-caller
Fix wrong caller
This commit is contained in:
@@ -180,15 +180,20 @@ func getPackageName(f string) string {
|
|||||||
|
|
||||||
// getCaller retrieves the name of the first non-logrus calling function
|
// getCaller retrieves the name of the first non-logrus calling function
|
||||||
func getCaller() *runtime.Frame {
|
func getCaller() *runtime.Frame {
|
||||||
|
|
||||||
// cache this package's fully-qualified name
|
// cache this package's fully-qualified name
|
||||||
callerInitOnce.Do(func() {
|
callerInitOnce.Do(func() {
|
||||||
pcs := make([]uintptr, 2)
|
pcs := make([]uintptr, maximumCallerDepth)
|
||||||
_ = runtime.Callers(0, pcs)
|
_ = runtime.Callers(0, pcs)
|
||||||
logrusPackage = getPackageName(funcName(pcs))
|
|
||||||
|
|
||||||
// now that we have the cache, we can skip a minimum count of known-logrus functions
|
// dynamic get the package name and the minimum caller depth
|
||||||
// XXX this is dubious, the number of frames may vary
|
for i := 0; i < maximumCallerDepth; i++ {
|
||||||
|
funcName := runtime.FuncForPC(pcs[i]).Name()
|
||||||
|
if strings.Contains(funcName, "getCaller") {
|
||||||
|
logrusPackage = getPackageName(funcName)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
minimumCallerDepth = knownLogrusFrames
|
minimumCallerDepth = knownLogrusFrames
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
// +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()
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// +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()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user