rfw(simple rotate file writer)
Warning: this project has been moved to https://github.com/gokits/rfw .
Package rfw is a simple rotate file writer that can rotate file dayly and be configured how many rotated files to remain. It implements io.WriteCloser
and can be used with many logger package easyly.
There are many logger package in golang ecosystem, but few provide ability to rotate log file. Though we can use logrotate to rotate log file, but it has some drawbacks
- when logrotate working, load of io increasing too(few of programs implements a custom signal to reopen log file)
- risk of lost some lines of log content
- difficult to use
See code sample below
// file name of rotated log file will be ./logfile-20190101 ...
logpath := "./logfile"
remaindays := 7
lw, err = rfw.NewWithOptions(logpath, rfw.WithCleanUp(remaindays))
if err != nil {
//...
}
//now you have a io.WriteCloser lw, you can use it with std logger
log.SetOutput(lw)
This package has been used in production for more than two years. It is ready for production use.
- [TODO] async log writing