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
|
||||
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
|
||||
depth := runtime.Callers(3, pcs)
|
||||
for i := 0; i < depth; i++ {
|
||||
|
@ -105,10 +110,7 @@ func getCaller() (method string) {
|
|||
fullFuncName = fullFuncName[idx:]
|
||||
}
|
||||
|
||||
matched, err := regexp.MatchString("logrus.*", fullFuncName)
|
||||
if err != nil {
|
||||
return "CALLER_LOOKUP_FAILED"
|
||||
}
|
||||
matched := matchesLogrus.MatchString(fullFuncName)
|
||||
|
||||
// If the caller isn't part of logrus, we're done
|
||||
if !matched {
|
||||
|
|
Loading…
Reference in New Issue