mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
pass handler attrs to TerminalFormat as a parameter instead of adding them to record. add unit test for this
This commit is contained in:
parent
dad6ef06fe
commit
14bc27f178
1 changed files with 18 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
)
|
||||
|
||||
// TestLoggingWithVmodule checks that vmodule works.
|
||||
|
|
@ -26,6 +28,22 @@ func TestLoggingWithVmodule(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTerminalHandlerWithAttrs(t *testing.T) {
|
||||
out := new(bytes.Buffer)
|
||||
glog := NewGlogHandler(TerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")}))
|
||||
glog.Verbosity(LevelTrace)
|
||||
logger := NewLogger(glog)
|
||||
logger.Trace("a message", "foo", "bar")
|
||||
have := out.String()
|
||||
// The timestamp is locale-dependent, so we want to trim that off
|
||||
// "INFO [01-01|00:00:00.000] a messag ..." -> "a messag..."
|
||||
have = strings.Split(have, "]")[1]
|
||||
want := " a message baz=bat foo=bar\n"
|
||||
if have != want {
|
||||
t.Errorf("\nhave: %q\nwant: %q\n", have, want)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTraceLogging(b *testing.B) {
|
||||
SetDefault(NewLogger(TerminalHandler(os.Stderr, true)))
|
||||
b.ResetTimer()
|
||||
|
|
|
|||
Loading…
Reference in a new issue