Skip to content

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

License

Notifications You must be signed in to change notification settings

Me1onRind/logrotate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/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
    }
}

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages