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().
Variables
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
type Writer struct {
sync.Mutex
// 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
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
func (r *Writer) Close() error
Close closes the current file. Writer is unusable after this is called.
func (*Writer) SetKeep
func (r *Writer) SetKeep(n int)
SetKeep sets the number of archived files to keep.
func (*Writer) SetMax
func (r *Writer) SetMax(size int)
SetMax sets the maximum size for a file in bytes.
func (*Writer) Write
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.