Closed phuslu closed 3 years ago
we should not add a gzip support, it will reduce filewriter concurrency, because each lock -> compress -> write -> unlock
will significantly increase the lock hold time.
in conclusion, we shall use AsyncWriter
with gzip instead, An example
logger := log.Logger{
Level: log.InfoLevel,
Writer: &log.AsyncWriter{
ChannelSize: 100,
Writer: log.IOWriter{gzip.NewWriter(&log.FileWriter{
Filename: "main.log",
FileMode: 0600,
MaxSize: 50*1024*1024,
MaxBackups: 7,
LocalTime: false,
})},
},
}
Above logger will compress & write []byte in a standalone goroutine.
introduce extra CPU latency maybe save IO latency, give a try?