Documentation ¶
Overview ¶
package rotatelog is a port of File-RotateLog from Perl (https://metacpan.org/release/File-RotateLog), 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 ¶
const ( OptKeyClock = "clock" OptKeyLinkName = "link-name" OptKeyMaxAge = "max-age" OptKeyRotationTime = "rotation-time" OptKeyRotationCount = "rotation-count" )
Variables ¶
var Local = clockFn(time.Now)
Local is an object satisfying the Clock interface, which returns the current time in the local timezone
var UTC = clockFn(func() time.Time { return time.Now().UTC() })
UTC is an object satisfying the Clock interface, which returns the current time in UTC
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option interface { Name() string Value() interface{} }
Option is used to pass optional arguments to the RotateLog constructor
func WithClock ¶
WithClock creates a new Option that sets a clock that the RotateLogs object will use to determine the current time.
By default rotatelogs.Local, which returns the current time in the local time zone, is used. If you would rather use UTC, use rotatelogs.UTC as the argument to this option, and pass it to the constructor.
func WithLinkName ¶
WithLinkName creates a new Option that sets the symbolic link name that gets linked to the current file name being used.
func WithLocation ¶
WithLocation creates a new Option that sets up a "Clock" interface that the RotateLogs object will use to determine the current time.
This optin works by always returning the in the given location.
func WithMaxAge ¶
WithMaxAge creates a new Option that sets the max age of a log file before it gets purged from the file system.
func WithRotationCount ¶
WithRotationCount creates a new Option that sets the number of files should be kept before it gets purged from the file system.
func WithRotationTime ¶
WithRotationTime creates a new Option that sets the time between rotation.
type RotateLog ¶
type RotateLog struct {
// contains filtered or unexported fields
}
RotateLog represents a log file that gets automatically rotated as you write to it.
func New ¶
New creates a new RotateLog object. A log filename pattern must be passed. Optional `Option` parameters may be passed
func (*RotateLog) Close ¶
Close satisfies the io.Closer interface. You must call this method if you performed any writes to the object.
func (*RotateLog) CurrentFileName ¶
CurrentFileName returns the current file name that the RotateLog object is writing to
func (*RotateLog) Rotate ¶
Rotate forcefully rotates the log files. If the generated file name clash because file already exists, a numeric suffix of the form ".1", ".2", ".3" and so forth are appended to the end of the log file
Thie method can be used in conjunction with a signal handler so to emulate servers that generate new log files when they receive a SIGHUP
type RotatelogHook ¶
type RotatelogHook struct {
// contains filtered or unexported fields
}
SyslogHook to send logs via syslog.
func NewHook ¶
func NewHook(p string, options ...Option) (*RotatelogHook, error)
Creates a hook to be added to an instance of logger. This is called with `hook, err := NewHook("./access_log.%Y%m%d",
WithLinkName("./access_log"), WithMaxAge(24 * time.Hour), WithRotationTime(time.Hour), WithClock(UTC))`
`if err == nil { log.Hooks.Add(hook.SetFormatter(&logrus.JSONFormatter{})) }`
func (*RotatelogHook) Close ¶
func (hook *RotatelogHook) Close() error
func (*RotatelogHook) Levels ¶
func (hook *RotatelogHook) Levels() []logrus.Level
func (*RotatelogHook) SetFormatter ¶
func (hook *RotatelogHook) SetFormatter(formatter logrus.Formatter) *RotatelogHook