-
Notifications
You must be signed in to change notification settings - Fork 16
/
files.go
49 lines (44 loc) · 1000 Bytes
/
files.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
46
47
48
49
package logx
import (
"github.com/robfig/cron/v3"
"gopkg.in/natefinch/lumberjack.v2"
"io"
)
type FilesLogger struct {
Path string
MaxSize int
MaxAge int
MaxBackups int
IsUTC bool
IsCompress bool
}
func getFilesWriter(fl FilesLogger) (io.Writer, error) {
if fl.MaxAge == 0 {
fl.MaxAge = 7
}
log := lumberjack.Logger{
Filename: fl.Path,
MaxSize: fl.MaxSize,
MaxAge: fl.MaxAge,
MaxBackups: fl.MaxBackups,
LocalTime: !fl.IsUTC,
Compress: fl.IsCompress,
}
c := cron.New()
// c.AddFunc("* * * * * *", func() { lj_log.Rotate() })
c.AddFunc("@daily", func() { log.Rotate() })
c.Start()
//hook, err := rotatelogs.New(
// strings.Replace(fl.Path, ".log", "", -1)+"-%Y%m%d.log",
// rotatelogs.WithLinkName(fl.Path),
// rotatelogs.WithMaxAge(fl.MaxAge),
// rotatelogs.WithRotationSize(fl.MaxSize),
// rotatelogs.WithRotationTime(fl.RotationTime),
//)
//
//if err != nil {
// return nil, err
//}
//return hook, nil
return &log, nil
}