MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / main

Function main

example/logs/main.go:11–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func main() {
12
13 // DEBUG log
14 logs.Debugf("this is debug message %s", "hello world")
15
16 // set log config
17 logs.SetLogConfig(func(n *logs.LogConfig) {
18 // close DEBUG log
19 n.Debug = false
20 })
21
22 // this message will be ignore
23 logs.Debug("this is debug message")
24
25 logs.Infof("this is info message %d", 123)
26
27 // WARN log
28 logs.Warn("warn!")
29
30 // ERROR log will print error stack
31 logs.Error(errors.New("test error"))
32
33 // custom log format
34 logs.RegisterOut(func(level logs.Level, format string, v ...any) {
35 log.SetPrefix(fmt.Sprintf("{CUSTOM} level:%d ", level))
36 if format == "" {
37 log.Output(3, fmt.Sprint(v...))
38 } else {
39 log.Output(3, fmt.Sprintf(format, v...))
40 }
41 })
42
43 logs.Debug("custom log")
44
45}

Callers

nothing calls this directly

Calls 7

DebugfFunction · 0.92
SetLogConfigFunction · 0.92
DebugFunction · 0.92
InfofFunction · 0.92
WarnFunction · 0.92
ErrorFunction · 0.92
RegisterOutFunction · 0.92

Tested by

no test coverage detected