File tree 2 files changed +11
-7
lines changed
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"
7
7
8
8
import (
9
9
"context"
10
+ "fmt"
10
11
"log"
11
12
"os"
12
13
"strings"
@@ -78,19 +79,22 @@ func (ts *testSink) LogEntry(ctx context.Context, ent slog.SinkEntry) {
78
79
// The testing package logs to stdout and not stderr.
79
80
entryhuman .Fmt (& sb , os .Stdout , ent )
80
81
81
- s := sb .String ()
82
-
83
82
switch ent .Level {
84
83
case slog .LevelDebug , slog .LevelInfo , slog .LevelWarn :
85
- ts .tb .Log (s )
84
+ ts .tb .Log (sb . String () )
86
85
case slog .LevelError , slog .LevelCritical :
87
86
if ts .opts .IgnoreErrors {
88
- ts .tb .Log (s )
87
+ ts .tb .Log (sb . String () )
89
88
} 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 ())
91
94
}
92
95
case slog .LevelFatal :
93
- ts .tb .Fatal (s )
96
+ sb .WriteString ("\n *** slogtest: FATAL log detected; TEST FAILURE ***" )
97
+ ts .tb .Fatal (sb .String ())
94
98
}
95
99
}
96
100
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ func TestCleanup(t *testing.T) {
55
55
fn ()
56
56
}
57
57
58
- // This shoud not log since the logger was cleaned up.
58
+ // This should not log since the logger was cleaned up.
59
59
l .Info (bg , "hello" )
60
60
assert .Equal (t , "no logs" , 0 , tb .logs )
61
61
}
You can’t perform that action at this time.
0 commit comments