@@ -26,7 +26,7 @@ func TestLoggingWithVmodule(t *testing.T) {
2626 logger .Trace ("a message" , "foo" , "bar" )
2727 have := out .String ()
2828 // The timestamp is locale-dependent, so we want to trim that off
29- // "INFO [01-01|00:00:00.000] a messag ..." -> "a messag ..."
29+ // "INFO [01-01|00:00:00.000] a message ..." -> "a message ..."
3030 have = strings .Split (have , "]" )[1 ]
3131 want := " a message foo=bar\n "
3232 if have != want {
@@ -42,14 +42,33 @@ func TestTerminalHandlerWithAttrs(t *testing.T) {
4242 logger .Trace ("a message" , "foo" , "bar" )
4343 have := out .String ()
4444 // The timestamp is locale-dependent, so we want to trim that off
45- // "INFO [01-01|00:00:00.000] a messag ..." -> "a messag ..."
45+ // "INFO [01-01|00:00:00.000] a message ..." -> "a message ..."
4646 have = strings .Split (have , "]" )[1 ]
4747 want := " a message baz=bat foo=bar\n "
4848 if have != want {
4949 t .Errorf ("\n have: %q\n want: %q\n " , have , want )
5050 }
5151}
5252
53+ // Make sure the default json handler outputs debug log lines
54+ func TestJSONHandler (t * testing.T ) {
55+ out := new (bytes.Buffer )
56+ handler := JSONHandler (out )
57+ logger := slog .New (handler )
58+ logger .Debug ("hi there" )
59+ if len (out .String ()) == 0 {
60+ t .Error ("expected non-empty debug log output from default JSON Handler" )
61+ }
62+
63+ out .Reset ()
64+ handler = JSONHandlerWithLevel (out , slog .LevelInfo )
65+ logger = slog .New (handler )
66+ logger .Debug ("hi there" )
67+ if len (out .String ()) != 0 {
68+ t .Errorf ("expected empty debug log output, but got: %v" , out .String ())
69+ }
70+ }
71+
5372func BenchmarkTraceLogging (b * testing.B ) {
5473 SetDefault (NewLogger (NewTerminalHandler (os .Stderr , true )))
5574 b .ResetTimer ()
@@ -78,7 +97,7 @@ func benchmarkLogger(b *testing.B, l Logger) {
7897 tt = time .Now ()
7998 bigint = big .NewInt (100 )
8099 nilbig * big.Int
81- err = errors .New ("Oh nooes it's crap" )
100+ err = errors .New ("oh nooes it's crap" )
82101 )
83102 b .ReportAllocs ()
84103 b .ResetTimer ()
@@ -107,7 +126,7 @@ func TestLoggerOutput(t *testing.T) {
107126 tt = time.Time {}
108127 bigint = big .NewInt (100 )
109128 nilbig * big.Int
110- err = errors .New ("Oh nooes it's crap" )
129+ err = errors .New ("oh nooes it's crap" )
111130 smallUint = uint256 .NewInt (500_000 )
112131 bigUint = & uint256.Int {0xff , 0xff , 0xff , 0xff }
113132 )
@@ -131,7 +150,7 @@ func TestLoggerOutput(t *testing.T) {
131150
132151 have := out .String ()
133152 t .Logf ("output %v" , out .String ())
134- want := `INFO [11-07|19:14:33.821] This is a message foo=123 bytes="[0 0 0 0 0 0 0 0 0 0]" bonk="a string with text" time=0001-01-01T00:00:00+0000 bigint=100 nilbig=<nil> err="Oh nooes it's crap" struct="{A:Foo B:12}" struct="{A:Foo\nLinebreak B:122}" ptrstruct="&{A:Foo B:12}" smalluint=500,000 bigUint=1,600,660,942,523,603,594,864,898,306,482,794,244,293,965,082,972,225,630,372,095
153+ want := `INFO [11-07|19:14:33.821] This is a message foo=123 bytes="[0 0 0 0 0 0 0 0 0 0]" bonk="a string with text" time=0001-01-01T00:00:00+0000 bigint=100 nilbig=<nil> err="oh nooes it's crap" struct="{A:Foo B:12}" struct="{A:Foo\nLinebreak B:122}" ptrstruct="&{A:Foo B:12}" smalluint=500,000 bigUint=1,600,660,942,523,603,594,864,898,306,482,794,244,293,965,082,972,225,630,372,095
135154`
136155 if ! bytes .Equal ([]byte (have )[25 :], []byte (want )[25 :]) {
137156 t .Errorf ("Error\n have: %q\n want: %q" , have , want )
0 commit comments