-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlumberjack.go
31 lines (28 loc) · 1.25 KB
/
lumberjack.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
package main
import "github.com/feymanlee/logit"
// Options 传入 LumberjacSink ,并在 OutputPaths 中添加对应 scheme 就能将日志保存到文件并自动 rotate
func main() {
// scheme 为 lumberjack ,日志文件为 /tmp/x.log , 保存 7 天,保留 10 份文件,文件大小超过 100M ,使用压缩备份,压缩文件名使用 localtime
sink := logit.NewLumberjackSink("/tmp/x.log", 7, 10, 100, true, true)
err := logit.RegisterSink("lumberjack", sink)
if err != nil {
panic(err)
}
options := logit.Options{
// 使用 sink 中设置的 scheme 即 lumberjack: 或 lumberjack:// 并指定保存日志到指定文件,日志文件将自动按 LumberjackSink 的配置做 rotate
OutputPaths: []string{"lumberjack:"},
}
logger, _ := logit.NewLogger(options)
logger.Debug("xxx")
sink2 := logit.NewLumberjackSink("/tmp/x2.log", 7, 10, 100, true, true)
err = logit.RegisterSink("lumberjack2", sink2)
if err != nil {
panic(err)
}
options2 := logit.Options{
// 使用 sink 中设置的 scheme 即 lumberjack: 或 lumberjack:// 并指定保存日志到指定文件,日志文件将自动按 LumberjackSink 的配置做 rotate
OutputPaths: []string{"lumberjack2:"},
}
logger2, _ := logit.NewLogger(options2)
logger2.Debug("yyy")
}