rolling_file_appender

package
v0.0.0-...-a8ae166 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_ROTATE_SERIAL_NUM = 1000000000

Variables

This section is empty.

Functions

func IsCloseError

func IsCloseError(err error) bool

func IsDecodeError

func IsDecodeError(err error) bool

func IsEncodeError

func IsEncodeError(err error) bool

func IsMinorRotationError

func IsMinorRotationError(err error) bool

func IsNoFileError

func IsNoFileError(err error) bool

func IsOpenError

func IsOpenError(err error) bool

func IsRenameError

func IsRenameError(err error) bool

func IsStatError

func IsStatError(err error) bool

func IsSyncError

func IsSyncError(err error) bool

func IsWriteError

func IsWriteError(err error) bool

func NewBuilder

func NewBuilder(filename string, maxFileSize int64, maxDuration time.Duration, maxRotatedLogs int, rotateIfExists bool, headerGenerator func() []string) *rollingFileAppenderBuilder

NewBuilder returns a new rollingFileAppenderBuilder. You can directly call Build() to create a new RollingFileAppender, or configure additional options first.

filename is path to the file to log to. It can be a relative path (with respect to the current working directory) or an absolute path.

maxFileSize is the approximate file size that will be allowed before the log file is rotated. Rotated log files will have suffix of the form .YYYY-MM-DDTHH-MM-SS or .YYYY-MM-DDTHH-MM-SS-N (where N is an incrementing serial number used to resolve conflicts) appended to them. Set maxFileSize to a non-positive number if you wish there to be no limit.

maxDuration is how long to wait before rotating the log file. Set to 0 if you do not want log rotation to be time-based.

If both maxFileSize and maxDuration are set than the log file will be rotated whenever either threshold is met. The duration used to determine whether a log file should be rotated (that is, the duration compared to maxDuration) is reset regardless of why the log was rotated previously.

maxRotatedLogs specifies the maximum number of rotated logs allowed before old logs are deleted. Set to a non-positive number if you do not want old log files to be deleted.

If rotateIfExists is set to true and a log file with the same filename already exists, then the current one will be rotated. If rotateIfExists is set to false and a log file with the same filename already exists, then the current log file will be appended to. If a log file with the same filename does not exist, then a new log file is created regardless of the value of rotateIfExists.

As RotatingFileAppender might be wrapped by an AsyncAppender, an errHandler can be provided that will be called when an error occurs. It can set to nil if you do not want to provide one.

The return value headerGenerator, if not nil, is logged at the beginning of every log file.

Note that after building a RollingFileAppender with Build(), you will probably want to defer a call to RollingFileAppender's Close() (or at least Flush()). This ensures that in case of program exit (normal or panicking) that any pending logs are logged.

Types

type CloseError

type CloseError struct {
	Filename string
	Err      error
}

func (CloseError) Error

func (self CloseError) Error() string

type DecodeError

type DecodeError struct {
	Filename string
	Err      error
}

func (DecodeError) Error

func (self DecodeError) Error() string

type EncodeError

type EncodeError struct {
	Filename string
	Err      error
}

func (EncodeError) Error

func (self EncodeError) Error() string

type MinorRotationError

type MinorRotationError struct {
	Err error
}

func (MinorRotationError) Error

func (self MinorRotationError) Error() string

type NoFileError

type NoFileError struct{}

func (NoFileError) Error

func (NoFileError) Error() string

type OpenError

type OpenError struct {
	Filename string
	Err      error
}

func (OpenError) Error

func (self OpenError) Error() string

type RenameError

type RenameError struct {
	OldFilename string
	NewFilename string
	Err         error
}

func (RenameError) Error

func (self RenameError) Error() string

type RollingFileAppender

type RollingFileAppender struct {
	// contains filtered or unexported fields
}

func New

func New(filename string, maxFileSize int64, maxDuration time.Duration, maxRotatedLogs int, rotateIfExists bool, headerGenerator func() []string) (*RollingFileAppender, error)

New creates a new RollingFileAppender.

This is deprecated in favor of calling NewBuilder().Build()

func NewWithStringWriter

func NewWithStringWriter(filename string, maxFileSize int64, maxDuration time.Duration, maxRotatedLogs int, rotateIfExists bool, headerGenerator func() []string, stringWriterCallback func(*os.File) slogger.StringWriter) (*RollingFileAppender, error)

func (*RollingFileAppender) Append

func (self *RollingFileAppender) Append(log *slogger.Log) error

func (*RollingFileAppender) Close

func (self *RollingFileAppender) Close() error

func (*RollingFileAppender) Flush

func (self *RollingFileAppender) Flush() error

func (*RollingFileAppender) Reopen

func (self *RollingFileAppender) Reopen() error

Useful for manual log rotation. For example, logrotated may rename the log file and then ask us to reopen it. Before reopening it we will be writing to the renamed log file. After reopening we will be writing to a new log file with the original name.

func (*RollingFileAppender) Rotate

func (self *RollingFileAppender) Rotate() error

type RotationTime

type RotationTime struct {
	Time     time.Time
	Serial   int
	Filename string
}

type RotationTimeSlice

type RotationTimeSlice [](*RotationTime)

func (RotationTimeSlice) Len

func (self RotationTimeSlice) Len() int

func (RotationTimeSlice) Less

func (self RotationTimeSlice) Less(i, j int) bool

func (RotationTimeSlice) Swap

func (self RotationTimeSlice) Swap(i, j int)

type StatError

type StatError struct {
	Filename string
	Err      error
}

func (StatError) Error

func (self StatError) Error() string

type SyncError

type SyncError struct {
	Filename string
	Err      error
}

func (SyncError) Error

func (self SyncError) Error() string

type WriteError

type WriteError struct {
	Filename string
	Err      error
}

func (WriteError) Error

func (self WriteError) Error() string

Jump to

Keyboard shortcuts

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