-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_test.go
90 lines (67 loc) · 2.25 KB
/
example_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package jlo_test
import (
"fmt"
"os"
"github.com/dcmn-com/jlo"
)
func ExampleLogLevel_String() {
level := jlo.DebugLevel.String()
fmt.Println(level)
// Output: debug
}
func ExampleNewLogger() {
l := jlo.NewLogger(os.Stdout)
l.FieldKeyLevel = "lvl"
l.FieldKeyMsg = "msg"
l.FieldKeyTime = "time"
l.Infof("I'm real")
// Output: {"lvl":"info","msg":"I'm real","time":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleNewLogger_customFields() {
l := jlo.NewLogger(os.Stdout)
l.Infof("I'm real")
// Output: {"@level":"info","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_Debugf() {
l := jlo.NewLogger(os.Stdout)
l.SetLogLevel(jlo.DebugLevel)
l.Debugf("I'm real")
// Output: {"@level":"debug","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_Infof() {
l := jlo.NewLogger(os.Stdout)
l.Infof("I'm real")
// Output: {"@level":"info","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_Warnf() {
l := jlo.NewLogger(os.Stdout)
l.Warnf("I'm real")
// Output: {"@level":"warning","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_Errorf() {
l := jlo.NewLogger(os.Stdout)
l.Errorf("I'm real")
// Output: {"@level":"error","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_Fatalf() {
l := jlo.NewLogger(os.Stdout)
l.Fatalf("I'm real")
// Output: {"@level":"fatal","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_SetLogLevel() {
l := jlo.NewLogger(os.Stdout)
l.SetLogLevel(jlo.DebugLevel)
l.Debugf("I'm real")
// Output: {"@level":"debug","@message":"I'm real","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_WithField() {
l := jlo.NewLogger(os.Stdout)
l = l.WithField("@request_id", "aa33ee55")
l.Infof("I'm real")
// Output: {"@level":"info","@message":"I'm real","@request_id":"aa33ee55","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}
func ExampleLogger_WithField_Chaining() {
l := jlo.NewLogger(os.Stdout)
l.WithField("@request_id", "aa33ee55").Infof("I'm real")
// Output: {"@level":"info","@message":"I'm real","@request_id":"aa33ee55","@timestamp":"2018-08-02T21:48:56.856339554Z"}
}