mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
log: add test for withattrs
This commit is contained in:
parent
7a27285f37
commit
15221dc431
1 changed files with 29 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ func TestLoggingWithVmodule(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestLoggingWithVmoduleDowngrade checks that vmodule can be downgraded.
|
||||||
func TestLoggingWithVmoduleDowngrade(t *testing.T) {
|
func TestLoggingWithVmoduleDowngrade(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false))
|
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false))
|
||||||
|
|
@ -62,6 +63,34 @@ func TestLoggingWithVmoduleDowngrade(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestWithAttrsVerbosityChange checks that verbosity changes affect child loggers.
|
||||||
|
func TestWithAttrsVerbosityChange(t *testing.T) {
|
||||||
|
out := new(bytes.Buffer)
|
||||||
|
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false))
|
||||||
|
glog.Verbosity(LevelInfo)
|
||||||
|
|
||||||
|
// Create a child logger with an extra attribute.
|
||||||
|
child := slog.New(glog.WithAttrs([]slog.Attr{slog.String("peer", "foo")}))
|
||||||
|
|
||||||
|
// Debug should be filtered at Info level.
|
||||||
|
child.Debug("this should be filtered")
|
||||||
|
if bytes.Contains(out.Bytes(), []byte("this should be filtered")) {
|
||||||
|
t.Fatal("expected debug message to be filtered at Info level")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change verbosity on the parent to allow Debug.
|
||||||
|
glog.Verbosity(LevelDebug)
|
||||||
|
|
||||||
|
// Child should pick up the new level and include its attributes.
|
||||||
|
child.Debug("this should be logged")
|
||||||
|
if !bytes.Contains(out.Bytes(), []byte("this should be logged")) {
|
||||||
|
t.Fatal("expected child logger to pick up verbosity change")
|
||||||
|
}
|
||||||
|
if !bytes.Contains(out.Bytes(), []byte("peer=foo")) {
|
||||||
|
t.Fatal("expected child logger to include WithAttrs attributes")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTerminalHandlerWithAttrs(t *testing.T) {
|
func TestTerminalHandlerWithAttrs(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")}))
|
glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")}))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue