Documentation
¶
Index ¶
- Constants
- func CompressMatcher(format CompressFormat) *regexMatcher
- func Compressor(format CompressFormat) *compressor
- func DefaultMatcher() *regexMatcher
- func DefaultProcessor() *defaultProcessor
- func IntervalChecker(interval time.Duration) *intervalChecker
- func IsAlpha(s string) bool
- func IsAlphanumeric(s string) bool
- func IsNumeric(s string) bool
- func MaxAgeFilter(maxAge time.Duration) (obj *maxAgeFilter)
- func MaxBackupsFilter(maxBackups int) *maxBackupsFilter
- func MaxSizeChecker(maxSize int64) *maxSizeChecker
- func NewRegexMatcher(suffixPattern string) *regexMatcher
- func SetDebug(enabled bool)
- type Checker
- type CompressFormat
- type Filter
- type Matcher
- type Option
- type OptionFunc
- type Processor
- type Roll
- func (r *Roll) Close() error
- func (r *Roll) Open() error
- func (r *Roll) WithChecker(c ...Checker) *Roll
- func (r *Roll) WithDefaultChecker(c RollCheckerConf) *Roll
- func (r *Roll) WithDefaultFilter(c RollFilterConf) *Roll
- func (r *Roll) WithDefaultMatcher() *Roll
- func (r *Roll) WithDefaultProcessor() *Roll
- func (r *Roll) WithFilter(f ...Filter) *Roll
- func (r *Roll) WithMatcher(m Matcher) *Roll
- func (r *Roll) WithOptions(opts ...Option) *Roll
- func (r *Roll) WithProcessor(p Processor) *Roll
- func (r *Roll) Write(p []byte) (n int, err error)
- type RollCheckerConf
- type RollConf
- type RollFilterConf
- type Rstat
- func (r *Rstat) Birthtimespec() (bool, syscall.Timespec)
- func (r *Rstat) Checked() bool
- func (r *Rstat) FileInfo() fs.FileInfo
- func (r *Rstat) IsDir() bool
- func (r *Rstat) Lock()
- func (r *Rstat) ModTime() time.Time
- func (r *Rstat) Mode() fs.FileMode
- func (r *Rstat) Name() string
- func (r *Rstat) RLock()
- func (r *Rstat) RUnlock()
- func (r *Rstat) SetChecked(checked bool)
- func (r *Rstat) Size() int64
- func (r *Rstat) String() string
- func (r *Rstat) Unlock()
Constants ¶
const ( DurOneDay = 24 * time.Hour DurOneWeek = 7 * 24 * time.Hour )
const ( SizeKB = 1024 SizeMB = 1024 * 1024 )
Variables ¶
This section is empty.
Functions ¶
func CompressMatcher ¶ added in v1.2.0
func CompressMatcher(format CompressFormat) *regexMatcher
CompressMatcher matches the file names with the .1.gz suffix
eg. app.log app.log.1.gz app.log.2.gz ...
func Compressor ¶ added in v1.2.0
func Compressor(format CompressFormat) *compressor
Compressor compresses and rename the files
eg.
base: "abc.log", return: "abc.log.1.gz"
func DefaultMatcher ¶
func DefaultMatcher() *regexMatcher
DefaultMatcher matches the simple file names
eg. app.log app.log.1 app.log.2 ...
func DefaultProcessor ¶
func DefaultProcessor() *defaultProcessor
DefaultProcessor renames the files, increase the tail number of the file name.
func IntervalChecker ¶
IntervalChecker checks whether a file should be rolled at regular intervals
If interval <= 0, it will never roll.
func IsAlphanumeric ¶
IsAlphanumeric checks if the string contains only Unicode letters or digits.
func IsNumeric ¶
IsNumeric Checks if the string contains only digits. A decimal point is not a digit and returns false.
func MaxAgeFilter ¶
MaxAgeFilter filter files by age
func MaxBackupsFilter ¶
func MaxBackupsFilter(maxBackups int) *maxBackupsFilter
MaxSizeFilter filter files by size
func MaxSizeChecker ¶
func MaxSizeChecker(maxSize int64) *maxSizeChecker
MaxSizeChecker checks whether a file should be rolled when its size(bytes) exceeds maxSize
func NewRegexMatcher ¶ added in v1.2.0
func NewRegexMatcher(suffixPattern string) *regexMatcher
Types ¶
type Checker ¶
Checker is a file checker, it checks if a file is shall be rolled.
func DefaultChecker ¶
func DefaultChecker(c RollCheckerConf) []Checker
type CompressFormat ¶ added in v1.2.0
type CompressFormat string
const ( NoCompress CompressFormat = "" Gzip CompressFormat = "gzip" Zlib CompressFormat = "zlib" )
type Filter ¶
type Filter interface { Name() string Filter(input []os.DirEntry) (remains []os.DirEntry, filtered []os.DirEntry, err error) DealFiltered(dir string, filtered []os.DirEntry) error }
Filter filters out the sorted-by-filename files that need to be processed
func DefaultFilter ¶
func DefaultFilter(c RollFilterConf) []Filter
type Matcher ¶
type Matcher interface { // Match return true if other file base name matches Match(other string) bool // Init the matcher with the file's base name Init(base string) }
Matcher mathes the files for further processing
type Option ¶ added in v1.2.0
type Option interface {
// contains filtered or unexported methods
}
func Compress ¶ added in v1.2.0
func Compress(format CompressFormat) Option
Compress specifies the format of the compressed file
type OptionFunc ¶ added in v1.3.0
type OptionFunc func(r *Roll)
type Processor ¶
type Processor interface { // Process process the remaining files after filtering Process(dir string, remains []os.DirEntry) error }
Processor processes the remaining files after filtering
type Roll ¶
type Roll struct {
// contains filtered or unexported fields
}
func NewC ¶
NewC creates a customizable Roll
The following components need to be populated:
- Checker
- Mather
- Filter
- Processor
func (*Roll) WithChecker ¶
func (*Roll) WithDefaultChecker ¶
func (r *Roll) WithDefaultChecker(c RollCheckerConf) *Roll
func (*Roll) WithDefaultFilter ¶
func (r *Roll) WithDefaultFilter(c RollFilterConf) *Roll
func (*Roll) WithDefaultMatcher ¶
func (*Roll) WithDefaultProcessor ¶
func (*Roll) WithFilter ¶
func (*Roll) WithMatcher ¶
func (*Roll) WithOptions ¶ added in v1.2.0
func (*Roll) WithProcessor ¶
type RollCheckerConf ¶
type RollConf ¶
type RollConf struct { FilePath string // file's location RollCheckerConf RollFilterConf }
type RollFilterConf ¶
type Rstat ¶
type Rstat struct {
// contains filtered or unexported fields
}
Rstat wraps os.FileInfo with local stored information about the file.
func (*Rstat) Birthtimespec ¶
Birthtimespec returns the file's birth time.