-
Notifications
You must be signed in to change notification settings - Fork 0
/
textwriter_test.go
40 lines (35 loc) · 1.03 KB
/
textwriter_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
package golog
import (
"context"
"errors"
"os"
"time"
)
func ExampleTextWriter() {
format := &Format{
TimestampFormat: "2006-01-02 15:04:05",
TimestampKey: "time",
LevelKey: "level",
MessageKey: "message",
}
writerConfig := NewTextWriterConfig(os.Stdout, format, NoColorizer)
config := NewConfig(&DefaultLevels, AllLevelsActive, writerConfig)
log := NewLogger(config)
// Use fixed time for reproducable example output
at, _ := time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05")
log.NewMessageAt(context.Background(), at, config.InfoLevel(), "My log message").
Int("int", 66).
Str("str", "Hello\tWorld!\n").
Log()
log.NewMessageAt(context.Background(), at, config.ErrorLevel(), "Something went wrong!").
Err(errors.New("Multi\nLine\n\"Error\"")).
Int("numberOfTheBeast", 666).
Log()
// Output:
// 2006-01-02 15:04:05 |INFO | My log message int=66 str="Hello\tWorld!\n"
// 2006-01-02 15:04:05 |ERROR| Something went wrong! error=`
// Multi
// Line
// "Error"
// ` numberOfTheBeast=666
}