-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_test.go
More file actions
47 lines (37 loc) · 1.01 KB
/
logger_test.go
File metadata and controls
47 lines (37 loc) · 1.01 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
package logger
import (
"fmt"
"github.com/rs/zerolog"
"testing"
"time"
)
func TestNewLogger(t *testing.T) {
l := NewLogger(nil)
fmt.Println(l.GetLevel().String())
l.SetLevel(zerolog.DebugLevel)
fmt.Println(l.GetLevel().String())
l.CustomContext(func(ctx zerolog.Context) zerolog.Logger {
return ctx.
Str("project", "project-a").
Str("module", "module-a").
Int64("program_start_at", time.Now().Unix()).
Logger()
})
// Note the difference in the `unix_milli` values in the two log outputs
l.CustomEvent(func(event *zerolog.Event, level zerolog.Level) *zerolog.Event {
return event.Int64("unix_milli", time.Now().UnixMilli())
})
// callers
l.CustomEvent(func(event *zerolog.Event, level zerolog.Level) *zerolog.Event {
if level > zerolog.InfoLevel {
callers := CalledLists(Callers(0))
fmt.Print(string(callers))
event.Bytes("callers", callers)
}
return event
})
l.Info().Msg("123")
<-time.After(time.Second * 2)
l.Error().Err(fmt.Errorf("321")).Send()
l.Trace().Msg("000")
}