File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package slogtest // import "cdr.dev/slog/sloggers/slogtest"
77
88import (
99 "context"
10+ "fmt"
1011 "log"
1112 "os"
1213 "strings"
@@ -78,19 +79,22 @@ func (ts *testSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
7879 // The testing package logs to stdout and not stderr.
7980 entryhuman .Fmt (& sb , os .Stdout , ent )
8081
81- s := sb .String ()
82-
8382 switch ent .Level {
8483 case slog .LevelDebug , slog .LevelInfo , slog .LevelWarn :
85- ts .tb .Log (s )
84+ ts .tb .Log (sb . String () )
8685 case slog .LevelError , slog .LevelCritical :
8786 if ts .opts .IgnoreErrors {
88- ts .tb .Log (s )
87+ ts .tb .Log (sb . String () )
8988 } else {
90- ts .tb .Error (s )
89+ sb .WriteString (fmt .Sprintf (
90+ "\n *** slogtest: log detected at level %s; TEST FAILURE ***" ,
91+ ent .Level ,
92+ ))
93+ ts .tb .Error (sb .String ())
9194 }
9295 case slog .LevelFatal :
93- ts .tb .Fatal (s )
96+ sb .WriteString ("\n *** slogtest: FATAL log detected; TEST FAILURE ***" )
97+ ts .tb .Fatal (sb .String ())
9498 }
9599}
96100
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ func TestCleanup(t *testing.T) {
5555 fn ()
5656 }
5757
58- // This shoud not log since the logger was cleaned up.
58+ // This should not log since the logger was cleaned up.
5959 l .Info (bg , "hello" )
6060 assert .Equal (t , "no logs" , 0 , tb .logs )
6161}
You can’t perform that action at this time.
0 commit comments