Documentation ¶
Overview ¶
Package rollwriter provides a high performance rolling file log. Package rollwriter does not print logs, but implements io.Writer. It can coordinate with any logs which depends on io.Writer, such as golang standard log. Main features:
- support rolling logs by file size.
- support rolling logs by datetime.
- support scavenging expired or useless logs.
- support compressing logs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncOption ¶
type AsyncOption func(*AsyncOptions)
AsyncOption modifies the AsyncOptions.
func WithDropLog ¶
func WithDropLog(b bool) AsyncOption
WithDropLog returns an AsyncOption which set whether to drop logs on log queue full.
func WithLogQueueSize ¶
func WithLogQueueSize(n int) AsyncOption
WithLogQueueSize returns an AsyncOption which sets log queue size.
func WithWriteLogInterval ¶
func WithWriteLogInterval(n int) AsyncOption
WithWriteLogInterval returns an AsyncOption which sets log interval(ms) threshold(ms).
func WithWriteLogSize ¶
func WithWriteLogSize(n int) AsyncOption
WithWriteLogSize returns an AsyncOption which sets log size(Byte) threshold.
type AsyncOptions ¶
type AsyncOptions struct { // LogQueueSize is the queue size of asynchronous log. LogQueueSize int // WriteLogSize is the threshold to write async log. WriteLogSize int // WriteLogInterval is the time interval to write async log. WriteLogInterval int // DropLog determines whether to discard logs when log queue is full. DropLog bool }
AsyncOptions is the call options of AsyncRollWriter.
type AsyncRollWriter ¶
type AsyncRollWriter struct {
// contains filtered or unexported fields
}
AsyncRollWriter is the asynchronous rolling log writer which implements zapcore.WriteSyncer.
func NewAsyncRollWriter ¶
func NewAsyncRollWriter(logger io.WriteCloser, opt ...AsyncOption) *AsyncRollWriter
NewAsyncRollWriter creates a new AsyncRollWriter.
func (*AsyncRollWriter) Close ¶
func (w *AsyncRollWriter) Close() error
Close closes current log file. It implements io.Closer.
func (*AsyncRollWriter) Sync ¶
func (w *AsyncRollWriter) Sync() error
Sync syncs logs. It implements zapcore.WriteSyncer.
type Option ¶
type Option func(*Options)
Option modifies the Options.
func WithCompress ¶
WithCompress returns an Option which sets whether log files should be compressed.
func WithMaxAge ¶
WithMaxAge returns an Option which sets the max expire time(Day) of log files.
func WithMaxBackups ¶
WithMaxBackups returns an Option which sets the max number of backup log files.
func WithMaxSize ¶
WithMaxSize returns an Option which sets the max size(MB) of log files.
func WithRotationTime ¶
WithRotationTime returns an Option which sets the time format(%Y%m%d) to roll logs.
type Options ¶
type Options struct { // MaxSize is max size by byte of the log file. MaxSize int64 // MaxBackups is the max number of log files. MaxBackups int // MaxAge is the max expire time by day of log files. MaxAge int // whether the log file should be compressed. Compress bool // TimeFormat is the time format to split log file by time. TimeFormat string }
Options is the RollWriter call options.
type RollWriter ¶
type RollWriter struct {
// contains filtered or unexported fields
}
RollWriter is a file log writer which support rolling by size or datetime. It implements io.WriteCloser.
func NewRollWriter ¶
func NewRollWriter(filePath string, opt ...Option) (*RollWriter, error)
NewRollWriter creates a new RollWriter.
func (*RollWriter) Close ¶
func (w *RollWriter) Close() error
Close closes the current log file. It implements io.Closer.