From 86a84a9d1856ec270a040060bbb4ad59c6f75478 Mon Sep 17 00:00:00 2001 From: Alex S Date: Thu, 27 Feb 2020 11:04:36 +0800 Subject: [PATCH] Get right logrus package name --- entry.go | 2 +- versions_go1_14.go | 10 ++++++++++ versions_others.go | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 versions_go1_14.go create mode 100644 versions_others.go diff --git a/entry.go b/entry.go index 5c971f69b..1bf127c3b 100644 --- a/entry.go +++ b/entry.go @@ -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 diff --git a/versions_go1_14.go b/versions_go1_14.go new file mode 100644 index 000000000..8db33606a --- /dev/null +++ b/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() +} diff --git a/versions_others.go b/versions_others.go new file mode 100644 index 000000000..8b3a68204 --- /dev/null +++ b/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() +}