Documentation ¶
Overview ¶
package logrotate provides a clean simple way to implement log file writing with rotation of the logfiles, e.g. after a certain time or beyond a certain size. Log rotation can depend on operating system signals and can be used with Linux 'logrotate'.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustLogWriterWithSignals ¶ added in v0.6.0
MustLogWriterWithSignals opens a log file for writing and attaches a signal handler (signals.RunOnPoke) to it. Therefore, when the program receives SIGHUP or SIGUSR1, it will close then reopen the log file, allowing log rotation to happen.
Note that the logName may be blank or "-", in which case the defaultWriter will be used instead of a log file; there is no signal handler in this case.
If an error arises, this will cause a panic.
func NewLogWriterWithSignals ¶ added in v0.6.0
NewLogWriterWithSignals opens a log file for writing and attaches a signal handler (signals.RunOnPoke) to it. Therefore, when the program receives SIGHUP or SIGUSR1, it will close then reopen the log file, allowing log rotation to happen.
Note that the logName may be blank or "-", in which case the defaultWriter will be used instead of a log file; there is no signal handler in this case.
Types ¶
type ReopenWriter ¶
type ReopenWriter interface { io.Writer io.Closer FileName() string Open() error WriteString(s string) (n int, err error) }
ReopenWriter is a WriteCloser that is able to close and reopen cleanly whilst in use. It is intended for writing log files, so always appends to existing files instead of truncating them.
This will work well with the 'logrotate' utility on Linux. On rotation, 'logrotate' should rename the old file and then signal to the application, e.g. via SIGHUP or SIGUSR1.
func NewReopenWriter ¶
func NewReopenWriter(fileName string) ReopenWriter
NewReopenWriter returns a new reopener with a given filename. The filename stays constant even when the file is closed and reopened.