Documentation ¶
Index ¶
Constants ¶
const (
// TimeFormat is the default format used for the suffix date and time on each rotated log.
TimeFormat = "2006-01-02_1504"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { TimeFormat string TimeFormatAsPrefix bool RotateDaily bool Compress bool MaximumSize int64 }
Options allows you to customize tne behavior of a RotatingWriter.
type RotatingWriter ¶
RotatingWriter is a io.Writer which wraps a *os.File, suitable for log rotation.
func NewWriter ¶
func NewWriter(filename string, opts *Options) (*RotatingWriter, error)
NewWriter creates a new file and returns a rotating writer.
func NewWriterFromFile ¶
func NewWriterFromFile(file *os.File, opts *Options) (*RotatingWriter, error)
NewWriterFromFile creates a rotating writer using the provided file as base.
The caller must take care to not close the file it provides here, as the RotatingWriter will do it automatically when rotating.
func (*RotatingWriter) Write ¶
func (w *RotatingWriter) Write(b []byte) (int, error)
Write implements the io.Writer interface.
NOTE(vincent): the rotating is not perfect when you want to rotate based on the maximum size. We won't rotate in the middle of a call to Write, so a call to Write will either end up in the original file or the new file if it needs to be rotated. That is to say, a call to Write will never split up the data from b into two different files. With this you can see that, given a big enough b, the original file CAN be significantly bigger than the requested maximum size. However, in practice it will never be a problem:
- the std package log will always write small buffers
- if you use your own logger, you should never use a big buffer anyway.