push compilation even higher, to reduce to one call

This commit is contained in:
Dave Clendenan
2016-11-28 16:22:33 -08:00
parent 8161d932a1
commit 1e21450408
+8 -6
View File
@@ -13,12 +13,17 @@ import (
var bufferPool *sync.Pool
// regex for validation is external, to reduce compilation overhead
var matchesLogrus *regexp.Regexp
func init() {
bufferPool = &sync.Pool{
New: func() interface{} {
return new(bytes.Buffer)
},
}
matchesLogrus, _ = regexp.Compile("logrus.*")
}
// Defines the key when adding errors using WithError.
@@ -51,11 +56,13 @@ type Entry struct {
}
func NewEntry(logger *Logger) *Entry {
return &Entry{
entry := &Entry{
Logger: logger,
// Default is three fields, plus one optional. Give a little extra room.
Data: make(Fields, 6),
}
return entry
}
// Returns the string representation from the reader and ultimately the
@@ -96,11 +103,6 @@ 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++ {