Learn from https://github.com/lestrrat-go/file-rotatelogs. But rotate driven by time.Timer so more fast.
package main
import (
"fmt"
"github.com/Me1onRind/logrotate"
"time"
)
func main() {
logPath := "./log/data.log.2006010215"
writer, err := logrotate.NewRoteteLog(
logPath,
logrotate.WithRotateTime(time.Hour),
logrotate.WithCurLogLinkname("./log/data.log"),
logrotate.WithDeleteExpiredFile(time.Hour*24*7, "data.log.*"),
)
if err != nil {
fmt.Println(err)
return
}
defer writer.Close()
if _, err := writer.Write([]byte("Hello,World!\n")); err != nil {
fmt.Println(err)
return
}
}
File Rotate Interval
Link to latest logfile(hard link)
Judege expired by laste modify time.
Only delete satisfying file wildcard filename
Log file retention time.
Deleted file wildcard