Niexiawei / logrotate

A Lightweight and concurrency safe rotate log io.Writer. Trigger rotate event by time.Timer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logrotate

fork https://github.com/Me1onRind/logrotate

Learn from https://github.com/lestrrat-go/file-rotatelogs. But rotate driven by time.Timer so more fast.

Example

package main

import (
    "fmt"
	"github.com/Niexiawei/logrotate"
    "time"
)

func main() {
    logPath := "./log/data.log.2006010215"
    writer, err := logrotate.NewRotateLog(
        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
    }
}

configuration

RotateTime

File Rotate Interval

CurLogLinkname

Link to latest logfile(hard link)

DeleteExpiredFile

Judege expired by laste modify time.

Only delete satisfying file wildcard filename

maxAge

Log file retention time.

fileWilcard

Deleted file wildcard

About

A Lightweight and concurrency safe rotate log io.Writer. Trigger rotate event by time.Timer.

License:MIT License


Languages

Language:Go 100.0%