rotate: Index | Files

package rotate

import ""

Package rotate implements a Writer that will write to files in a directory and rotate them when they reach a specific size. It will also only keep a fixed number of files. It can be used anywhere an io.Writer is used, for example in log.SetOutput().


Package Files



var FilePerm = os.FileMode(0666)

FilePerm defines the permissions that Writer will use for all the files it creates.

var RootPerm = os.FileMode(0755)

RootPerm defines the permissions that Writer will use if it needs to create the root directory.

type Writer Uses

type Writer struct {
    // contains filtered or unexported fields

Writer implements the io.Writer interface and writes to the "current" file in the root directory. When current's size exceeds max, it is renamed and a new file is created.

func New Uses

func New(root, prefix string) (*Writer, error)

New creates a new Writer. The files will be created in the root directory. root will be created if necessary. The filenames will start with prefix.

func (*Writer) Close Uses

func (r *Writer) Close() error

Close closes the current file. Writer is unusable after this is called.

func (*Writer) SetKeep Uses

func (r *Writer) SetKeep(n int)

SetKeep sets the number of archived files to keep.

func (*Writer) SetMax Uses

func (r *Writer) SetMax(size int)

SetMax sets the maximum size for a file in bytes.

func (*Writer) Write Uses

func (r *Writer) Write(p []byte) (n int, err error)

Write writes p to the current file, then checks to see if rotation is necessary.

Package rotate imports 8 packages (graph). Updated 2016-07-23. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).