go-pkg-hub / logrotate

go package for creating and rotating log files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logrotate

go package for creating and rotating log files

Usage

package main

import (
    "io"
    "github.com/go-pkg-hub/logrotate"
)

func OpenLogFile(file, maxSize string, maxFiles int) (io.WriteCloser, error) {
    opts := []logrotate.Option{
        logrotate.WithMaxSize(logrotate.StringToSize(maxSize)),
        logrotate.WithMaxFiles(maxFiles),
    }
    return logrotate.New(file, opts...)
}

func main() {
    file, err := OpenLogFile("/var/log/app.log", "1m", 3)
    //...
}

About

go package for creating and rotating log files

License:MIT License


Languages

Language:Go 100.0%