beats: Index | Files

package file

import ""


Package Files

file_other.go fileinfo.go fileinfo_unix.go helper_other.go interval_rotator.go rotator.go stderr_other.go


const MaxBackupsLimit = 1024

MaxBackupsLimit is the upper bound on the number of backup files. Any values greater will result in an error.

func IntervalLogIndex Uses

func IntervalLogIndex(filename string) (uint64, int, error)

IntervalLogIndex returns n as int given a log filename in the form [prefix]-[formattedDate]-n

func IsRemoved Uses

func IsRemoved(f *os.File) bool

IsRemoved checks wheter the file held by f is removed.

func OrderIntervalLogs Uses

func OrderIntervalLogs(filename string) string

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 Uses

func ReadOpen(path string) (*os.File, error)

ReadOpen opens a file for reading only

func RedirectStandardError Uses

func RedirectStandardError(toFile *os.File) error

RedirectStandardError causes all standard error output to be directed to the given file.

func SafeFileRotate Uses

func SafeFileRotate(path, tempfile string) error

SafeFileRotate safely rotates an existing file under path and replaces it with the tempfile

type FileInfo Uses

type FileInfo interface {
    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 Uses

func Lstat(name string) (FileInfo, error)

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.

func Stat Uses

func Stat(name string) (FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

func Wrap Uses

func Wrap(info os.FileInfo) (FileInfo, error)

Wrap wraps the given os.FileInfo and returns a FileInfo in order to expose the UID and GID in a uniform manner across operating systems.

type Logger Uses

type Logger interface {
    Debugw(msg string, keysAndValues ...interface{}) // Debug

Logger allows the rotator to write debug information.

type Rotator Uses

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 Uses

func NewFileRotator(filename string, options ...RotatorOption) (*Rotator, error)

NewFileRotator returns a new Rotator.

func (*Rotator) Close Uses

func (r *Rotator) Close() error

Close closes the currently open file.

func (*Rotator) Rotate Uses

func (r *Rotator) Rotate() error

Rotate triggers a file rotation.

func (*Rotator) Sync Uses

func (r *Rotator) Sync() error

Sync commits the current contents of the file to stable storage. Typically, this means flushing the file system's in-memory copy of recently written data to disk.

func (*Rotator) Write Uses

func (r *Rotator) Write(data []byte) (int, error)

Write writes the given bytes to the file. This implements io.Writer. If the write would trigger a rotation the rotation is done before writing to avoid going over the max size. Write is safe for concurrent use.

type RotatorOption Uses

type RotatorOption func(r *Rotator)

RotatorOption is a configuration option for Rotator.

func Interval Uses

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 Uses

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 Uses

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 Uses

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 Uses

func RedirectStderr(redirect bool) RotatorOption

RedirectStderr causes all writes to standard error to be redirected to this rotator.

func RotateOnStartup Uses

func RotateOnStartup(b bool) RotatorOption

RotateOnStartup immediately rotates files on startup rather than appending to the existing file. The default is true.

func WithLogger Uses

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.

type StateOS Uses

type StateOS struct {
    Inode  uint64 `json:"inode,"`
    Device uint64 `json:"device,"`

func GetOSState Uses

func GetOSState(info os.FileInfo) StateOS

GetOSState returns the FileStateOS for non windows systems

func (StateOS) IsSame Uses

func (fs StateOS) IsSame(state StateOS) bool

IsSame file checks if the files are identical

func (StateOS) String Uses

func (fs StateOS) String() string

Package file imports 11 packages (graph) and is imported by 323 packages. Updated 2020-04-26. Refresh now. Tools for package owners.