Documentation ¶
Overview ¶
Package `rotate` provides an io.Writer interface for files that will detect when the open file has been rotated away (due to log rotation, or manual move/deletion) and re-open it. This allows the standard log.Logger to continue working as expected after log rotation happens (without needing to specify the `copytruncate` or equivalient options).
This package is safe to use concurrently from multiple goroutines
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RotatableFileWriter ¶
RotatableFileWriter implementation that knows when the file has been rotated and re-opens it
func NewRotatableFileWriter ¶
func NewRotatableFileWriter( name string, retries int, create bool, mode os.FileMode) (*RotatableFileWriter, error)
NewRotatableFileWriter opens a file for appending and writing that can be safely rotated.
If retries is greater than 0, RotatableFileWriter will make that number of additional attempts to reopen a rotated file after a file open failure, following a 1ms delay. This option can mitigate race conditions that may occur when RotatableFileWriter reopens the file while an underlying file manager, such as logrotate, is recreating the file and setting its properties.
When create is true, RotatableFileWriter will attempt to create the file (using mode), if it does not exist, when reopening the file. Set create to false to avoid conflicts with an underlying file manager, such as logrotate. logrotate, unless configured with nocreate, creates files with O_EXCL and re-rotates/retries if another process has created the file.
func (*RotatableFileWriter) Close ¶
func (f *RotatableFileWriter) Close() error
Close closes the underlying file
func (*RotatableFileWriter) Reopen ¶
func (f *RotatableFileWriter) Reopen() error
Reopen provides the concurrency safe implementation of re-opening the file, and updating the struct's fileInfo