From af6ac8cee616a8cd9f2b2afaa78dc66c7d420495 Mon Sep 17 00:00:00 2001 From: Fabrizio Cirelli Date: Mon, 9 Mar 2020 12:36:52 +0100 Subject: [PATCH 1/2] Fix wrong caller --- entry.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/entry.go b/entry.go index 1bf127c3b..defb8bc66 100644 --- a/entry.go +++ b/entry.go @@ -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 }) From fa25593b151851537e388f0bf1703fffa5c6af84 Mon Sep 17 00:00:00 2001 From: Fabrizio Cirelli Date: Mon, 9 Mar 2020 14:45:58 +0100 Subject: [PATCH 2/2] Removed useless files --- versions_go1_14.go | 10 ---------- versions_others.go | 10 ---------- 2 files changed, 20 deletions(-) delete mode 100644 versions_go1_14.go delete mode 100644 versions_others.go diff --git a/versions_go1_14.go b/versions_go1_14.go deleted file mode 100644 index 8db33606a..000000000 --- a/versions_go1_14.go +++ /dev/null @@ -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() -} diff --git a/versions_others.go b/versions_others.go deleted file mode 100644 index 8b3a68204..000000000 --- a/versions_others.go +++ /dev/null @@ -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() -}