Documentation ¶
Index ¶
- Constants
- func IsCloseError(err error) bool
- func IsDecodeError(err error) bool
- func IsEncodeError(err error) bool
- func IsMinorRotationError(err error) bool
- func IsNoFileError(err error) bool
- func IsOpenError(err error) bool
- func IsRenameError(err error) bool
- func IsStatError(err error) bool
- func IsSyncError(err error) bool
- func IsWriteError(err error) bool
- func NewBuilder(filename string, maxFileSize int64, maxDuration time.Duration, ...) *rollingFileAppenderBuilder
- type CloseError
- type DecodeError
- type EncodeError
- type MinorRotationError
- type NoFileError
- type OpenError
- type RenameError
- type RollingFileAppender
- type RotationTime
- type RotationTimeSlice
- type StatError
- type SyncError
- type WriteError
Constants ¶
const MAX_ROTATE_SERIAL_NUM = 1000000000
Variables ¶
This section is empty.
Functions ¶
func IsCloseError ¶
func IsDecodeError ¶
func IsEncodeError ¶
func IsMinorRotationError ¶
func IsNoFileError ¶
func IsOpenError ¶
func IsRenameError ¶
func IsStatError ¶
func IsSyncError ¶
func IsWriteError ¶
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 ¶
func (CloseError) Error ¶
func (self CloseError) Error() string
type DecodeError ¶
func (DecodeError) Error ¶
func (self DecodeError) Error() string
type EncodeError ¶
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 RenameError ¶
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 (*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 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 WriteError ¶
func (WriteError) Error ¶
func (self WriteError) Error() string