Documentation
¶
Index ¶
Constants ¶
const ( // RotateSecondly rotate every second RotateSecondly = 1 // RotateMinutely rorate every minute RotateMinutely = 60 * RotateSecondly // RotateHourly rotate every hour RotateHourly = 60 * RotateMinutely // RotateDaily rotate every day RotateDaily = 24 * RotateHourly // RotateWeekly rotate every week RotateWeekly = 7 * RotateDaily )
Variables ¶
var (
ErrClosed = errors.New("write stream closed")
)
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer interface {
io.WriteCloser
// Flush writes any data in the buffer to underlying writer.
Flush() error
}
Buffer interface defines buffer's common behaviors used by Rollout. A Buffer must implement io.WriteCloser interface. A Flush method is used to flush data to underlying writer before Rollout closes.
type BufferFunc ¶
BufferFunc is function to generate a new Buffer.
type BufferWriter ¶
type BufferWriter struct {
// contains filtered or unexported fields
}
func NewWriterSize ¶
func NewWriterSize(w io.Writer, size int) *BufferWriter
NewWriterSize returns a new Writer whose buffer has at least the specified size. If the argument io.Writer is already a Writer with large enough size, it returns the underlying Writer.
func (*BufferWriter) Available ¶
func (b *BufferWriter) Available() int
Available returns how many bytes are unused in the buffer.
func (*BufferWriter) Buffered ¶
func (b *BufferWriter) Buffered() int
Buffered returns the number of bytes that have been written into the current buffer.
func (*BufferWriter) Flush ¶
func (b *BufferWriter) Flush() error
Flush writes any buffered data to the underlying io.Writer.
type FileBuffer ¶
type FileBuffer struct {
// contains filtered or unexported fields
}
FileBuffer is a thread safe file writer with buffer. It is used to reduce disk IO. Guarantee atomic in single process writing situation.
func (*FileBuffer) Close ¶
func (b *FileBuffer) Close() error
Close stops timer, flushes data, and closes the file.
type Options ¶
type Options struct {
// Template is a template string for output destination name. Useable variables are `Host`, `Pid` and `Time`.
// You can change time format by providing `TimeFormat` option.
// In the situation of multiple processes, it is highly recommended to add `{{.Pid}}` in the template to avoid
// writing conflicts. If you run multiple processes in docker in the same machine, and they all write to the
// same directory in the host, add `{{.Host}}` in the template.
Template string
// TimeFormat is format string for `Template`'s Time field value. Default is "2016-01-02".
TimeFormat string
// Root is prefix of output destination name. In the built-in file buffer, it is treated as file directory.
Root string
// Rotation is the frequency how often write to a new destination. Default is RotateDaily.
Rotation int
// Keeps is how many destination copies will be retained. Default is 30.
Keeps int
// BufferSize is the size of underlying buffer. Default is 4096.
BufferSize int
// Flush is the interval for buffer automaticly flushing. Default is 10.
Flush int
// BufferFunc is a function generating new buffer. Default value is the built-in NewFileBuffer.
BufferFunc BufferFunc
// Clock is function to get current time.
Clock Clock
}
Options is data for create Rollout instance.
type Rollout ¶
type Rollout struct {
// contains filtered or unexported fields
}
Rollout is an io.WriteCloser. It is used for writing logs to rolling files. Output Buffer is an interface, so you can define your own Buffer and BufferFunc to use another underlying writer other than built-in file buffer.
func (*Rollout) Close ¶
Close the writer. There may be data present in current buffer when main goroutine quits. Such data will lost if you don't flush it to the underlying writer. Close will flushes any data in the buffer to current logging file and then closes the file descriptor. So make sure Rollout is closed before main goroutine quits.