rotatefile

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultArchivePerm = 0750
	DefaultFilePerm    = 0640
	MaxSequence        = 99999
)

Variables

View Source
var (
	Error          = errors.New("rotatefile")
	ErrOption      = fmt.Errorf("%w option", Error)
	ErrMaxSequence = fmt.Errorf("%w maximum sequence %d reached", Error, MaxSequence)
)

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

func Open

func Open(name string, opts ...Option) (*File, error)

func (*File) Close

func (rf *File) Close() error

func (*File) Dir

func (rf *File) Dir() string

func (*File) Name

func (rf *File) Name() string

func (*File) OpenFile

func (rf *File) OpenFile(flag int) (*os.File, error)

File calls os.OpenFile with given flags. It returns a new file descriptor that shares the same underlying file, but does not replace internal file descriptor. Caller is responsible for closing the returned file descriptor.

func (*File) PreviousRotation

func (rf *File) PreviousRotation() time.Time

func (*File) Rotate

func (rf *File) Rotate() (err error)

func (*File) Rotations

func (rf *File) Rotations() int

func (*File) SELinuxContext

func (rf *File) SELinuxContext() (string, error)

SELinuxContext retrieves the file's SELinux context (e.g., "unconfined_u:object_r:config_home_t:s0").

func (*File) Stat

func (rf *File) Stat() (fsutils.FileInfo, error)

Stat retrieves the file's stats using unix.Statx.

func (*File) Write

func (rf *File) Write(p []byte) (n int, err error)

type Option

type Option func(*File) error

func ArchiveDir

func ArchiveDir(dir string, perm os.FileMode) Option

ArchiveDir sets the directory where rotated files will be archived. default is same directory. If directory does not exits it will be created. If mode is 0, DefaultArchiveDirMode will be used. If oprion is not set file is rotated in same directory.

func FileMode

func FileMode(mode fs.FileMode) Option

FileMode sets the file mode for the rotated files. If mode is 0, DefaultFileMode will be used.

func RotateOnOpen

func RotateOnOpen() Option

func RotatedFilePrefix

func RotatedFilePrefix(prefix string) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL