mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
log: avoid stack lookups when not needed/used
This commit is contained in:
parent
25733a4aad
commit
06d91bdd9f
2 changed files with 20 additions and 3 deletions
|
|
@ -177,19 +177,22 @@ type logger struct {
|
|||
}
|
||||
|
||||
func (l *logger) write(msg string, lvl Lvl, ctx []interface{}, skip int) {
|
||||
l.h.Log(&Record{
|
||||
record := &Record{
|
||||
Time: time.Now(),
|
||||
Lvl: lvl,
|
||||
Msg: msg,
|
||||
Ctx: newContext(l.ctx, ctx),
|
||||
Call: stack.Caller(skip),
|
||||
KeyNames: RecordKeyNames{
|
||||
Time: timeKey,
|
||||
Msg: msgKey,
|
||||
Lvl: lvlKey,
|
||||
Ctx: ctxKey,
|
||||
},
|
||||
})
|
||||
}
|
||||
if locationEnabled.Load() {
|
||||
record.Call = stack.Caller(skip)
|
||||
}
|
||||
l.h.Log(record)
|
||||
}
|
||||
|
||||
func (l *logger) New(ctx ...interface{}) Logger {
|
||||
|
|
|
|||
14
log/logger_test.go
Normal file
14
log/logger_test.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkTraceLogging(b *testing.B) {
|
||||
Root().SetHandler(LvlFilterHandler(LvlInfo, StreamHandler(os.Stderr, TerminalFormat(true))))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
Trace("a message", "v", i)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue