-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.go
43 lines (38 loc) · 956 Bytes
/
setup.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
package statKit
import (
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"github.com/richelieu-yang/chimera/v3/src/cronKit"
"github.com/richelieu-yang/chimera/v3/src/file/fileKit"
"github.com/richelieu-yang/chimera/v3/src/log/logrusKit"
"github.com/sirupsen/logrus"
)
var logger *logrus.Logger
func MustSetup(logPath string) {
if err := Setup(logPath); err != nil {
logrusKit.DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
func Setup(logPath string) error {
if strKit.IsBlank(logPath) {
// (1) 输出到: 控制台
} else {
// (2) 输出到: 文件日志
if err := fileKit.AssertNotExistOrIsFile(logPath); err != nil {
return err
}
f, err := fileKit.CreateInAppendMode(logPath)
if err != nil {
return err
}
logger = logrusKit.NewLogger(logrusKit.WithOutput(f))
}
c, _, err := cronKit.NewCronWithTask("@every 20s", func() {
PrintStats(logger)
})
if err != nil {
return err
}
c.Start()
return nil
}