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) {
|
func (l *logger) write(msg string, lvl Lvl, ctx []interface{}, skip int) {
|
||||||
l.h.Log(&Record{
|
record := &Record{
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
Lvl: lvl,
|
Lvl: lvl,
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
Ctx: newContext(l.ctx, ctx),
|
Ctx: newContext(l.ctx, ctx),
|
||||||
Call: stack.Caller(skip),
|
|
||||||
KeyNames: RecordKeyNames{
|
KeyNames: RecordKeyNames{
|
||||||
Time: timeKey,
|
Time: timeKey,
|
||||||
Msg: msgKey,
|
Msg: msgKey,
|
||||||
Lvl: lvlKey,
|
Lvl: lvlKey,
|
||||||
Ctx: ctxKey,
|
Ctx: ctxKey,
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
if locationEnabled.Load() {
|
||||||
|
record.Call = stack.Caller(skip)
|
||||||
|
}
|
||||||
|
l.h.Log(record)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) New(ctx ...interface{}) Logger {
|
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