forked from mirror/logrus
performance: precompile regex before iterating
This commit is contained in:
parent
473c3448ab
commit
8161d932a1
10
entry.go
10
entry.go
|
@ -96,6 +96,11 @@ func getCaller() (method string) {
|
||||||
// Restrict the lookback to 25 frames - if it's further than that, report UNKNOWN
|
// Restrict the lookback to 25 frames - if it's further than that, report UNKNOWN
|
||||||
pcs := make([]uintptr, 25)
|
pcs := make([]uintptr, 25)
|
||||||
|
|
||||||
|
matchesLogrus, err := regexp.Compile("logrus.*")
|
||||||
|
if err != nil {
|
||||||
|
return "CALLER_LOOKUP_FAILED"
|
||||||
|
}
|
||||||
|
|
||||||
// the first non-logrus caller is at least three frames away
|
// the first non-logrus caller is at least three frames away
|
||||||
depth := runtime.Callers(3, pcs)
|
depth := runtime.Callers(3, pcs)
|
||||||
for i := 0; i < depth; i++ {
|
for i := 0; i < depth; i++ {
|
||||||
|
@ -105,10 +110,7 @@ func getCaller() (method string) {
|
||||||
fullFuncName = fullFuncName[idx:]
|
fullFuncName = fullFuncName[idx:]
|
||||||
}
|
}
|
||||||
|
|
||||||
matched, err := regexp.MatchString("logrus.*", fullFuncName)
|
matched := matchesLogrus.MatchString(fullFuncName)
|
||||||
if err != nil {
|
|
||||||
return "CALLER_LOOKUP_FAILED"
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the caller isn't part of logrus, we're done
|
// If the caller isn't part of logrus, we're done
|
||||||
if !matched {
|
if !matched {
|
||||||
|
|
Loading…
Reference in New Issue