Documentation ¶
Index ¶
- Constants
- func IntervalLogIndex(filename string) (uint64, int, error)
- func IsRemoved(f *os.File) bool
- func OrderIntervalLogs(filename string) string
- func ReadOpen(path string) (*os.File, error)
- func RedirectStandardError(toFile *os.File) error
- func SafeFileRotate(path, tempfile string) error
- type FileInfo
- type Logger
- type Rotator
- type RotatorOption
- func Interval(d time.Duration) RotatorOption
- func MaxBackups(n uint) RotatorOption
- func MaxSizeBytes(n uint) RotatorOption
- func Permissions(m os.FileMode) RotatorOption
- func RedirectStderr(redirect bool) RotatorOption
- func RotateOnStartup(b bool) RotatorOption
- func WithLogger(l Logger) RotatorOption
- type StateOS
Constants ¶
const MaxBackupsLimit = 1024
MaxBackupsLimit is the upper bound on the number of backup files. Any values greater will result in an error.
Variables ¶
This section is empty.
Functions ¶
func IntervalLogIndex ¶
IntervalLogIndex returns n as int given a log filename in the form [prefix]-[formattedDate]-n
func IsRemoved ¶
IsRemoved checks wheter the file held by f is removed. On Windows IsRemoved reads the DeletePending flags using the GetFileInformationByHandleEx. A file is not removed/unlinked as long as at least one process still own a file handle. A delete file is only marked as deleted, and file attributes can still be read. Only opening a file marked with 'DeletePending' will fail.
func OrderIntervalLogs ¶
OrderIntervalLogs, when given a log filename in the form [prefix]-[formattedDate]-n returns the filename after zero-padding the trailing n so that foo-[date]-2 sorts before foo-[date]-10.
func ReadOpen ¶
ReadOpen opens a file for reading only As Windows blocks deleting a file when its open, some special params are passed here.
func RedirectStandardError ¶
RedirectStandardError causes all standard error output to be directed to the given file.
func SafeFileRotate ¶
SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile
Types ¶
type FileInfo ¶
type FileInfo interface { os.FileInfo UID() (int, error) // UID of the file owner. Returns an error on non-POSIX file systems. GID() (int, error) // GID of the file owner. Returns an error on non-POSIX file systems. }
A FileInfo describes a file and is returned by Stat and Lstat.
func Lstat ¶
Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
Rotator is a io.WriteCloser that automatically rotates the file it is writing to when it reaches a maximum size and optionally on a time interval basis. It also purges the oldest rotated files when the maximum number of backups is reached.
func NewFileRotator ¶
func NewFileRotator(filename string, options ...RotatorOption) (*Rotator, error)
NewFileRotator returns a new Rotator.
type RotatorOption ¶
type RotatorOption func(r *Rotator)
RotatorOption is a configuration option for Rotator.
func Interval ¶
func Interval(d time.Duration) RotatorOption
Interval sets the time interval for log rotation in addition to log rotation by size. The default is 0 for disabled.
func MaxBackups ¶
func MaxBackups(n uint) RotatorOption
MaxBackups configures the maximum number of backup files to save (not counting the active file). The upper limit is 1024 on this value is. The default is 7.
func MaxSizeBytes ¶
func MaxSizeBytes(n uint) RotatorOption
MaxSizeBytes configures the maximum number of bytes that a file should contain before being rotated. The default is 10 MiB.
func Permissions ¶
func Permissions(m os.FileMode) RotatorOption
Permissions configures the file permissions to use for the file that the Rotator creates. The default is 0600.
func RedirectStderr ¶
func RedirectStderr(redirect bool) RotatorOption
RedirectStderr causes all writes to standard error to be redirected to this rotator.
func RotateOnStartup ¶
func RotateOnStartup(b bool) RotatorOption
RotateOnStartup immediately rotates files on startup rather than appending to the existing file. The default is true.
func WithLogger ¶
func WithLogger(l Logger) RotatorOption
WithLogger injects a logger implementation for logging debug information. If no logger is injected then the no logging will occur.