push compilation even higher, to reduce to one call
This commit is contained in:
@@ -13,12 +13,17 @@ import (
|
|||||||
|
|
||||||
var bufferPool *sync.Pool
|
var bufferPool *sync.Pool
|
||||||
|
|
||||||
|
// regex for validation is external, to reduce compilation overhead
|
||||||
|
var matchesLogrus *regexp.Regexp
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
bufferPool = &sync.Pool{
|
bufferPool = &sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
return new(bytes.Buffer)
|
return new(bytes.Buffer)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchesLogrus, _ = regexp.Compile("logrus.*")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Defines the key when adding errors using WithError.
|
// Defines the key when adding errors using WithError.
|
||||||
@@ -51,11 +56,13 @@ type Entry struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewEntry(logger *Logger) *Entry {
|
func NewEntry(logger *Logger) *Entry {
|
||||||
return &Entry{
|
entry := &Entry{
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
// Default is three fields, plus one optional. Give a little extra room.
|
// Default is three fields, plus one optional. Give a little extra room.
|
||||||
Data: make(Fields, 6),
|
Data: make(Fields, 6),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the string representation from the reader and ultimately the
|
// 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
|
// 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++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user