-
Notifications
You must be signed in to change notification settings - Fork 116
/
main.go
45 lines (33 loc) · 821 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
40
41
42
43
44
45
package main
import (
"errors"
"fmt"
"log"
"github.com/xmirrorsecurity/opensca-cli/opensca/logs"
)
func main() {
// DEBUG log
logs.Debugf("this is debug message %s", "hello world")
// set log config
logs.SetLogConfig(func(n *logs.LogConfig) {
// close DEBUG log
n.Debug = false
})
// this message will be ignore
logs.Debug("this is debug message")
logs.Infof("this is info message %d", 123)
// WARN log
logs.Warn("warn!")
// ERROR log will print error stack
logs.Error(errors.New("test error"))
// custom log format
logs.RegisterOut(func(level logs.Level, format string, v ...any) {
log.SetPrefix(fmt.Sprintf("{CUSTOM} level:%d ", level))
if format == "" {
log.Output(3, fmt.Sprint(v...))
} else {
log.Output(3, fmt.Sprintf(format, v...))
}
})
logs.Debug("custom log")
}