rollwriter

package
v0.0.0-...-32ff608 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package rollwriter provides a high performance rolling file log. It can coordinate with any logs which depends on io.Writer, such as golang standard log. Main features:

  1. support rolling logs by file size.
  2. support rolling logs by datetime.
  3. support scavenging expired or useless logs.
  4. 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 create 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.

func (*AsyncRollWriter) Write

func (w *AsyncRollWriter) Write(data []byte) (int, error)

Write writes logs. It implements io.Writer.

type Option

type Option func(*Options)

Option modifies the Options.

func WithCompress

func WithCompress(b bool) Option

WithCompress returns an Option which sets whether log files should be compressed.

func WithMaxAge

func WithMaxAge(n int) Option

WithMaxAge returns an Option which sets the max expire time(Day) of log files.

func WithMaxBackups

func WithMaxBackups(n int) Option

WithMaxBackups returns an Option which sets the max number of backup log files.

func WithMaxSize

func WithMaxSize(n int) Option

WithMaxSize returns an Option which sets the max size(MB) of log files.

func WithRotationTime

func WithRotationTime(s string) Option

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.

func (*RollWriter) Write

func (w *RollWriter) Write(v []byte) (n int, err error)

Write writes logs. It implements io.Writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL