-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_logger.go
More file actions
53 lines (44 loc) · 1.39 KB
/
Copy pathtesting_logger.go
File metadata and controls
53 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package log
import (
"context"
"testing"
)
// NewTestingLogger returns a logger that uses `testing.T` logger
func NewTestingLogger(t *testing.T, name string) Logger {
if t == nil {
panic("t is nil")
}
if name == "" {
name = "*testingT"
}
return &testingLogger{t: t, name: name}
}
// testingLogger is tests
type testingLogger struct {
t *testing.T
name string
}
// Name returns the name of the logger.
func (logger *testingLogger) Name() string {
return logger.name
}
// Debugf logs a debug message.
func (logger *testingLogger) Debugf(ctx context.Context, format string, args ...interface{}) {
logger.t.Logf("Debug: "+format, args...)
}
// Infof is like Debugf, but at Info level.
func (logger *testingLogger) Infof(ctx context.Context, format string, args ...interface{}) {
logger.t.Logf("Info: "+format, args...)
}
// Warningf is like Debugf, but at Warning level.
func (logger *testingLogger) Warningf(ctx context.Context, format string, args ...interface{}) {
logger.t.Logf("Warning: "+format, args...)
}
// Errorf is like Debugf, but at Error level.
func (logger *testingLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
logger.t.Logf("Error: "+format, args...)
}
// Criticalf is like Debugf, but at Critical level.
func (logger *testingLogger) Criticalf(ctx context.Context, format string, args ...interface{}) {
logger.t.Logf("Critical: "+format, args...)
}