phuslu / log

Fastest structured logging
MIT License
672 stars 44 forks source link

enable gzip support to FileWriter #19

Closed phuslu closed 3 years ago

phuslu commented 3 years ago

introduce extra CPU latency maybe save IO latency, give a try?

phuslu commented 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.