Documentation
¶
Index ¶
Constants ¶
const ( OpCompress = "compress" OpListFiles = "list files" OpRemove = "remove file " OpOpen = "open file " OpClose = "close file " OpRename = "rename file " OpArchive = "archive" OpNewManager = "new manager" )
Variables ¶
var ( ErrFileClosed = errors.New("go-logicalfile/logicalfile: file already closed") ErrEmptyExt = errors.New("go-logicalfile/logicalfile: file extension must no be empty") ErrNilFunc = errors.New("go-logicalfile/logicalfile: compression function must no be nil") ErrInplace = errors.New("go-logicalfile/logicalfile: inplace compression is not supported") ErrNilWriter = errors.New("go-logicalfile/logicalfile: inner writer is nil. cannot write") )
Functions ¶
func ReplaceCompressor ¶
ReplaceCompressor replaces default compression method. It changes global state. ext should be file extension such as ".gz". Empty is not allowed. compress is the function that compress src file to dst file with the level. compress must not be nil.
Types ¶
type Error ¶
type Error struct {
Inner error // Inner is the inner error.
Op string // Op is the operation.
Msg string // Msg is the error message.
Detail string // Details is the error detail.
}
Error is the error type.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a logical file.
func (*File) Close ¶
Close closes the logical file. Once Close is called, this file cannot be used to write. It returns nil when the file is already closed.
func (*File) Rotate ¶
Rotate renew the underlying writer which means file rotation. Calling Rotate forces file rotation. It returns ErrFileClosed if the file has already been closed.
type FileConfig ¶
type FileConfig struct {
// ManagerConfig is the configuration of physical file manager.
ManagerConfig
// MaxBytes is the maximum size in bytes.
// Target writer will be renewed before exceeding the size.
// Zero or negative means no limit, or no writer rotation.
MaxBytes uint64
// RotateAt optionally specifies the time to rotate.
// RotateAt can be used for rotating physical file .
// RotateAt must return the future time.
RotateAt func() time.Time
// HandleError optionally handles errors occurred in a logical file.
HandleError func(error)
// Fallback is the function that called when writing to the
// current target io writer failed.
// If nil, os.Stderr.Write is used by default.
Fallback func([]byte) (int, error)
}
FileConfig is the configuration for a logical file. Use NewFile to create a new logical file.
type FileProvider ¶
FileProvider provides file as io writer.
type ManagerConfig ¶
type ManagerConfig struct {
// MaxAge is the maximum age to keep the archived files.
// Age is calculated based on the last modified time
// obtained by [io/fs.FileInfo].ModTime().
// Set UseParsedAge to true to calculate ages using
// the time parsed from archived files.
MaxAge time.Duration
// MaxHistory is the maximum number of archived files to keep.
// Zero or negative value means no limit.
MaxHistory int
// MaxTotalBytes is the maximum total byte size to keep archived files.
// Zero or negative value means no limit.
MaxTotalBytes uint64
// UseParsedAge, if true, calculate file ages based on the time
// parsed from archived file names.
// Note that time information must be contained in the Pattern.
// Missing time components are initialized to their minimum values.
// If %Y is not in the Pattern, it will be 1.
// If %M is not in the Pattern, it will be 1 (January).
// If %D is not in the Pattern, it will be 1.
// If %h is not in the Pattern, it will be 00.
// If %m is not in the Pattern, it will be 00.
// If %s is not in the Pattern, it will be 00.
UseParsedAge bool
// CompressLv specifies the compression level.
// Zero means no compression.
CompressLv int
// SrcDir is the directory containing source files.
// If empty, DstDir is used.
// If both SrcDir and DstDir are empty, current directory is used.
SrcDir string
// DstDir is the directory containing archived files.
// If empty, SrcDir is used.
// If both DstDir and SrcDir are empty, current directory is used.
DstDir string
// Pattern is the file name pattern to be manged.
// Pattern must not contain directories.
// Pattern must not be empty when ActiveFile is not specified.
// A ".%i" will be added when no specifiers are found.
// Following specifiers can be used in the pattern.
// %Y : YYYY 4 digits year. 0 <= YYYY
// %M : MM 2 digits month. 1 <= MM <= 12
// %D : DD 2 digits day of month. 1 <= DD <= 31
// %h : hh 2 digits hour. 0 <= hh <= 23
// %m : mm 2 digits minute. 0 <= mm <= 59
// %s : ss 2 digits second. 0 <= ss <= 59
// %u : unix second with free digits. 0 <= unix
// %i : index with free digits. 0 <= index
// %H : hostname
// %U : user id. "-1" on windows.
// %G : user group id. "-1" on windows.
// %p : pid (process id)
// %P : ppid (parent process id)
Pattern string
// ActiveFile is the file name that will be used for write target.
// ActiveFile is optional and can be used to use fixed file name.
// ActiveFile must not contain directories.
// Following specifiers can be used in the name.
// %H : hostname
// %U : user id. "-1" on windows.
// %G : user group id. "-1" on windows.
// %p : pid (process id)
// %P : ppid (parent process id)
ActiveFile string
}
ManagerConfig is the configuration for the physical file manager.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
all
command
|
|
|
cron
command
|
|
|
graceful-close
command
|
|
|
max-age
command
|
|
|
max-history
command
|
|
|
max-total
command
|
|
|
no-rotations
command
|