forked from phuslu/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogr_test.go
71 lines (53 loc) · 2 KB
/
logr_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package log
import (
"errors"
"testing"
)
type logrLogger interface {
Enabled() bool
Info(msg string, keysAndValues ...interface{})
Error(err error, msg string, keysAndValues ...interface{})
V(level int) *LogrLogger
WithValues(keysAndValues ...interface{}) *LogrLogger
WithName(name string) *LogrLogger
}
func TestLogrLoggerNil(t *testing.T) {
var logger *Logger
var logr logrLogger = logger.Logr(NewContext(nil).Str("tag", "hi logr").Value())
logr.Info("hello", "foo", "bar", "number", 42)
logr.Error(errors.New("this is a error"), "hello", "foo", "bar", "number", 42)
logr.V(0).Info("logr.V(0) OK.")
logr = logr.WithName("a_named_logger")
logr.Info("this is WithName test")
logr = logr.WithValues("a_key", "a_value")
logr.Info("this is WithValues test")
if logr.Enabled() {
logr.Info("logr.Enabled() OK.")
}
}
func TestLogrLogger(t *testing.T) {
DefaultLogger.Caller = 1
DefaultLogger.Writer = &ConsoleWriter{ColorOutput: true, EndWithMessage: true}
var logr logrLogger = DefaultLogger.Logr(NewContext(nil).Str("tag", "hi logr").Value())
logr.Info("hello", "foo", "bar", "number", 42)
logr.Error(errors.New("this is a error"), "hello", "foo", "bar", "number", 42)
logr.V(0).Info("logr.V(0) OK.")
logr = logr.WithName("a_named_logger")
logr.Info("this is WithName test")
logr = logr.WithValues("a_key", "a_value")
logr.Info("this is WithValues test")
if logr.Enabled() {
logr.Info("logr.Enabled() OK.")
}
}
func TestLogrLoggerLevel(t *testing.T) {
DefaultLogger.Caller = 1
DefaultLogger.Writer = &ConsoleWriter{ColorOutput: true, EndWithMessage: true}
var logr logrLogger = DefaultLogger.Logr(NewContext(nil).Str("tag", "hi logr").Value())
logr.(*LogrLogger).logger.Level = InfoLevel
logr.Info("hello", "foo", "bar", "number", 42)
logr.Error(errors.New("this is a error"), "hello", "foo", "bar", "number", 42)
logr.(*LogrLogger).logger.Level = ErrorLevel
logr.Info("hello", "foo", "bar", "number", 42)
logr.Error(errors.New("this is a error"), "hello", "foo", "bar", "number", 42)
}