dailyrotate: github.com/kjk/dailyrotate Index | Files

package dailyrotate

import "github.com/kjk/dailyrotate"

Package dailyrotate provides a file that is rotated daily (at midnight in specified location).

You provide a pattern for a file path. That pattern will be formatted with time.Format to generate a real path. It should be unique for each day e.g. 2006-01-02.txt.

You Write to a file and the code takes care of closing existing file and opening a new file when we're crossing daily boundaries.


Package Files


type File Uses

type File struct {

    Location *time.Location
    // contains filtered or unexported fields

File describes a file that gets rotated daily

func NewFile Uses

func NewFile(pathFormat string, onClose func(path string, didRotate bool)) (*File, error)

NewFile creates a new file that will be rotated daily (at midnight in specified location). pathFormat is file format accepted by time.Format that will be used to generate a name of the file. It should be unique in a given day e.g. 2006-01-02.txt. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes)

func (*File) Close Uses

func (f *File) Close() error

Close closes the file

func (*File) Flush Uses

func (f *File) Flush() error

Flush flushes the file

func (*File) Write Uses

func (f *File) Write(d []byte) (int, error)

Write writes data to a file

func (*File) Write2 Uses

func (f *File) Write2(d []byte, flush bool) (string, int64, int, error)

Write2 writes data to a file, optionally flushes. To enable users to later seek to where the data was written, it returns name of the file where data was written, offset at which the data was written, number of bytes and error

Package dailyrotate imports 5 packages (graph). Updated 2019-02-11. Refresh now. Tools for package owners.