rotate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

package rotate is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OptionFn

type OptionFn func(*RotateLogs) error

OptionFn is a type of Option that is represented by a single function that gets called for Configure()

func WithLinkName

func WithLinkName(s string) OptionFn

WithLinkName creates a new Option that sets the symbolic link name that gets linked to the current file name being used.

func WithMaxAge

func WithMaxAge(d time.Duration) OptionFn

WithMaxAge creates a new Option that sets the max age of a log file before it gets purged from the file system.

func WithRotationCount

func WithRotationCount(n int) OptionFn

WithRotationCount creates a new Option that sets the number of files should be kept before it gets purged from the file system.

func WithRotationTime

func WithRotationTime(d time.Duration) OptionFn

WithRotationTime creates a new Option that sets the time between rotation.

type RotateLogs

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

RotateLogs represents a log file that gets automatically rotated as you write to it.

func New

func New(pattern string, options ...OptionFn) (*RotateLogs, error)

New creates a new RotateLogs object. A log filename pattern must be passed. Optional `Option` parameters may be passed

func (*RotateLogs) Close

func (rl *RotateLogs) Close() error

Close satisfies the io.Closer interface. You must call this method if you performed any writes to the object.

func (*RotateLogs) CurrentFileName

func (rl *RotateLogs) CurrentFileName() string

CurrentFileName returns the current file name that the RotateLogs object is writing to

func (*RotateLogs) Write

func (rl *RotateLogs) Write(p []byte) (n int, err error)

Write satisfies the io.Writer interface. It writes to the appropriate file handle that is currently being used. If we have reached rotation time, the target file gets automatically rotated, and also purged if necessary.

Jump to

Keyboard shortcuts

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