-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
39 lines (33 loc) · 1.09 KB
/
file.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
package logger
import (
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
var writer zapcore.WriteSyncer
// Writer export log writer
func Writer() zapcore.WriteSyncer {
return writer
}
type File struct {
lumberjack.Logger
}
func (l *File) Sync() error {
return nil
}
// defaultFile returns a *File that implements the zapcore.WriteSyncer interface.
// filename is the file to write logs to.
// maxSize is the maximum size in megabytes of the log file before it gets rotated.
// maxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename.
// maxBackups is the maximum number of old log files to retain.
// localTime determines if the time used for formatting the timestamps in backup files is the computer's local time.
// compress determines if the rotated log files should be compressed using gzip.
func defaultFile() *File {
return &File{lumberjack.Logger{
Filename: file.Filename,
MaxSize: file.MaxSize,
MaxAge: file.MaxAge,
MaxBackups: file.MaxBackups,
LocalTime: file.LocalTime,
Compress: file.Compress,
}}
}