-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpterm_writer_test.go
More file actions
92 lines (75 loc) · 1.81 KB
/
Copy pathpterm_writer_test.go
File metadata and controls
92 lines (75 loc) · 1.81 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package pzlog
import (
"context"
"os"
"testing"
"time"
"github.com/rs/zerolog"
)
func TestMain(m *testing.M) {
log := zerolog.New(NewPtermWriter()).With().
Timestamp().
Stack().
Logger()
zerolog.TimeFieldFormat = time.DateTime
zerolog.SetGlobalLevel(zerolog.DebugLevel)
zerolog.DefaultContextLogger = &log
code := m.Run()
os.Exit(code)
}
func TestDebug(t *testing.T) {
log := zerolog.Ctx(context.TODO())
log.Debug().
Str("foo", "bar").
Int("number", 114514).
Bool("flag", true).
Dur("duration", time.Second).
Time("time", time.Now()).
Msg("debug case 1")
log.Debug().
Str("when were crayons invented", "1885").
Str("when was the first spaceflight", "1957").
Str("when did the first person land on the moon", "1969").
Msg("debug case 2")
}
func TestInfo(t *testing.T) {
log := zerolog.Ctx(context.TODO())
log.Info().
Str("foo", "bar").
Int("number", 114514).
Bool("flag", true).
Dur("duration", time.Second).
Time("time", time.Now()).
Msg("info case 1")
log.Info().
Int("what is the meaning of life", 42).
Int("what is the meaning of death", 0).
Msg("info case 2")
}
func TestWarn(t *testing.T) {
log := zerolog.Ctx(context.TODO())
log.Warn().
Str("foo", "bar").
Int("number", 114514).
Bool("flag", true).
Dur("duration", time.Second).
Time("time", time.Now()).
Msg("warn case 1")
log.Warn().
Str("Oh no, I see an error coming to us!", "Oh no, I see an error coming to us!").
Msg("warn case 2")
}
func TestError(t *testing.T) {
log := zerolog.Ctx(context.TODO())
log.Error().
Str("foo", "bar").
Int("number", 114514).
Bool("flag", true).
Dur("duration", time.Second).
Time("time", time.Now()).
Msg("error case 1")
log.Error().
Str("something bad happened", "something bad happened").
Int("error code", 114514).
Msg("error case 2")
}