rotation

package
v0.0.0-...-2d8c917 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package rotation provides triggering and rolling policy for system files.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoPolicy never triggers and does nothing when rolling.
	NoPolicy = &noPolicy{}
)

Functions

This section is empty.

Types

type File

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

File is a wrapper for file writer which supports rotation. Operations on File are not thread-safe.

func NewFile

func NewFile(name string) *File

NewFile creates a new file writer with the given name. Open() must be called before writing.

func (*File) Close

func (f *File) Close() error

Close closes the openning file.

func (*File) IsOpenned

func (f *File) IsOpenned() bool

IsOpenned checks whether file is openned.

func (*File) Open

func (f *File) Open() error

Open opens the file.

func (*File) OpenFile

func (f *File) OpenFile(flag int, perm os.FileMode) error

OpenFile opens the file with the given flag and permission.

func (*File) SetRollingPolicy

func (f *File) SetRollingPolicy(p RollingPolicy)

SetRollingPolicy sets a new RollingPolicy.

func (*File) SetTriggeringPolicy

func (f *File) SetTriggeringPolicy(p TriggeringPolicy)

SetTriggeringPolicy sets a new TriggeringPolicy.

func (*File) Write

func (f *File) Write(b []byte) (int, error)

Write must be called after Open().

type RollingPolicy

type RollingPolicy interface {
	Rollover(*os.File) error
}

RollingPolicy rolls over the log file.

type TimeRollingPolicy

type TimeRollingPolicy struct {
	FilePattern string
	FileCount   int

	TriggerTimer TriggerTimer
}

TimeRollingPolicy allows the roll over to be based on time. TODO: able to specify format.

func NewTimeRollingPolicy

func NewTimeRollingPolicy() *TimeRollingPolicy

NewTimeRollingPolicy allocates and returns a new TimeRollingPolicy.

func (*TimeRollingPolicy) Rollover

func (p *TimeRollingPolicy) Rollover(f *os.File) error

Rollover rolls the log file.

type TimeTriggeringPolicy

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

TimeTriggeringPolicy triggers when day changed. TODO: able to specify daily, weekly or monthly.

func NewTimeTriggeringPolicy

func NewTimeTriggeringPolicy() *TimeTriggeringPolicy

NewTimeTriggeringPolicy allocates and returns a TimeTriggeringPolicy.

func (*TimeTriggeringPolicy) IsTriggering

func (p *TimeTriggeringPolicy) IsTriggering(*os.File, []byte) bool

IsTriggering is called in Appender so it's only happens when an logging event happens.

func (*TimeTriggeringPolicy) Start

func (p *TimeTriggeringPolicy) Start() error

Start starts timer with current local time.

func (*TimeTriggeringPolicy) Stop

func (p *TimeTriggeringPolicy) Stop() error

Stop stops running timer.

func (*TimeTriggeringPolicy) TriggerTime

func (p *TimeTriggeringPolicy) TriggerTime() time.Time

TriggerTime returns the time trigger event was raised.

type TriggerTimer

type TriggerTimer interface {
	TriggerTime() time.Time
}

TriggerTimer returns trigger time

type TriggeringPolicy

type TriggeringPolicy interface {
	IsTriggering(*os.File, []byte) bool
}

TriggeringPolicy controls how rollingPolicy is activated.

Jump to

Keyboard shortcuts

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