mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
internal/testlog: when instantiating new logger via With, set logger handler reference as the bufHandler in the newly-instantiated logger instead of copying from parent
This commit is contained in:
parent
22c0605b68
commit
fbe86e3494
2 changed files with 23 additions and 1 deletions
|
|
@ -170,7 +170,8 @@ func (l *logger) Crit(msg string, ctx ...interface{}) {
|
|||
}
|
||||
|
||||
func (l *logger) With(ctx ...interface{}) log.Logger {
|
||||
return &logger{l.t, l.l.With(ctx...), l.mu, l.h}
|
||||
newLogger := l.l.With(ctx...)
|
||||
return &logger{l.t, newLogger, l.mu, newLogger.Handler().(*bufHandler)}
|
||||
}
|
||||
|
||||
func (l *logger) New(ctx ...interface{}) log.Logger {
|
||||
|
|
|
|||
21
internal/testlog/testlog_test.go
Normal file
21
internal/testlog/testlog_test.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package testlog
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLogging(t *testing.T) {
|
||||
l := Logger(t, log.LevelInfo)
|
||||
subLogger := l.New("foobar", 123)
|
||||
|
||||
l.Info("Visible")
|
||||
subLogger.Info("Hide and seek") // not visible due to sub buffer never being flushed
|
||||
l.Info("Also visible")
|
||||
|
||||
t.Log("flushed: ", l.Handler().(*bufHandler).buf)
|
||||
t.Log("remaining: ", subLogger.Handler().(*bufHandler).buf)
|
||||
// horrible hack to manually bring back the expected log data
|
||||
l.Handler().(*bufHandler).buf = subLogger.Handler().(*bufHandler).buf
|
||||
l.(*logger).flush()
|
||||
}
|
||||
Loading…
Reference in a new issue