()
| 9 | ) |
| 10 | |
| 11 | func 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 | } |
nothing calls this directly
no test coverage detected