-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (33 loc) · 842 Bytes
/
main.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
package main
import (
"encoding/json"
"os"
"strconv"
"github.com/nkmr-jp/zl"
"go.uber.org/zap"
)
func main() {
// Set Options
zl.SetLevel(zl.DebugLevel)
zl.SetOmitKeys(zl.HostnameKey)
// Initialize
zl.Init()
defer zl.Sync() // flush log buffer
// Write logs
zl.Info("USER_INFO", zap.String("user_name", "Alice"), zap.Int("user_age", 20)) // can use zap fields.
zl.Info("DISPLAY_TO_CONSOLE", zl.Console("The message you want to display to console"))
zl.Warn("WARN_MESSAGE")
zl.Debug("DEBUG_MESSAGE")
_, err := os.ReadFile("test")
zl.Err("READ_FILE_ERROR", err)
// zl.FatalErr("FATAL_READ_FILE_ERROR", err)
for i := 0; i < 2; i++ {
_, err = strconv.Atoi("one")
zl.Err("A_TO_I_ERROR", err)
}
for i := 0; i < 3; i++ {
v := ""
err = json.Unmarshal([]byte("test"), &v)
zl.Err("JSON_UNMARSHAL_ERROR", err)
}
}