Skip to content

Commit 567da6b

Browse files
authored
tlogger: print log type (#4774)
Error logs cause tests to fail. This makes it easier (possible) to find the error log
1 parent 03b2ebe commit 567da6b

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

internal/grpctest/tlogger.go

+25-10
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,23 @@ const callingFrame = 4
4141

4242
type logType int
4343

44+
func (l logType) String() string {
45+
switch l {
46+
case infoLog:
47+
return "INFO"
48+
case warningLog:
49+
return "WARNING"
50+
case errorLog:
51+
return "ERROR"
52+
case fatalLog:
53+
return "FATAL"
54+
}
55+
return "UNKNOWN"
56+
}
57+
4458
const (
45-
logLog logType = iota
59+
infoLog logType = iota
60+
warningLog
4661
errorLog
4762
fatalLog
4863
)
@@ -83,7 +98,7 @@ func (g *tLogger) log(ltype logType, depth int, format string, args ...interface
8398
g.t.Error(err)
8499
return
85100
}
86-
args = append([]interface{}{prefix}, args...)
101+
args = append([]interface{}{ltype.String() + " " + prefix}, args...)
87102
args = append(args, fmt.Sprintf(" (t=+%s)", time.Since(g.start)))
88103

89104
if format == "" {
@@ -180,35 +195,35 @@ func (g *tLogger) expected(s string) bool {
180195
}
181196

182197
func (g *tLogger) Info(args ...interface{}) {
183-
g.log(logLog, 0, "", args...)
198+
g.log(infoLog, 0, "", args...)
184199
}
185200

186201
func (g *tLogger) Infoln(args ...interface{}) {
187-
g.log(logLog, 0, "", args...)
202+
g.log(infoLog, 0, "", args...)
188203
}
189204

190205
func (g *tLogger) Infof(format string, args ...interface{}) {
191-
g.log(logLog, 0, format, args...)
206+
g.log(infoLog, 0, format, args...)
192207
}
193208

194209
func (g *tLogger) InfoDepth(depth int, args ...interface{}) {
195-
g.log(logLog, depth, "", args...)
210+
g.log(infoLog, depth, "", args...)
196211
}
197212

198213
func (g *tLogger) Warning(args ...interface{}) {
199-
g.log(logLog, 0, "", args...)
214+
g.log(warningLog, 0, "", args...)
200215
}
201216

202217
func (g *tLogger) Warningln(args ...interface{}) {
203-
g.log(logLog, 0, "", args...)
218+
g.log(warningLog, 0, "", args...)
204219
}
205220

206221
func (g *tLogger) Warningf(format string, args ...interface{}) {
207-
g.log(logLog, 0, format, args...)
222+
g.log(warningLog, 0, format, args...)
208223
}
209224

210225
func (g *tLogger) WarningDepth(depth int, args ...interface{}) {
211-
g.log(logLog, depth, "", args...)
226+
g.log(warningLog, depth, "", args...)
212227
}
213228

214229
func (g *tLogger) Error(args ...interface{}) {

0 commit comments

Comments
 (0)