Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
File describes a file that gets rotated daily
func NewFile ¶
NewFile creates a new file that will be rotated daily (at midnight in specified location). pathFormat is file format accepted by time.Format that will be used to generate a name of the file. It should be unique in a given day e.g. 2006-01-02.txt. If you need more flexibility, use NewFileWithPathGenerator which accepts a function that generates a file path. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes) Warning: time.Format might format more than you expect e.g. time.Now().Format(`/logs/dir-2/2006-01-02.txt`) will change "-2" in "dir-2" to current day. For better control over path generation, use NewFileWithPathGenerator
func NewFileWithPathGenerator ¶
func NewFileWithPathGenerator(pathGenerator func(time.Time) string, onClose func(path string, didRotate bool)) (*File, error)
NewFileWithPathGenerator creates a new file that will be rotated daily (at midnight in timezone specified by in specified location). pathGenerator is a function that will return a path for a daily log file. It should be unique in a given day e.g. time.Format of "2006-01-02.txt" creates a string unique for the day. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes)