Rotating log file with retention
This commit is contained in:
@@ -101,6 +101,34 @@ opened with @racket['replace], and the output is flushed after every line.
|
||||
Calling the procedure again replaces the existing file destination.
|
||||
}
|
||||
|
||||
@defproc[(sl-log-to-rotating-file
|
||||
[filename path-string?]
|
||||
[retention-days exact-positive-integer? 7])
|
||||
void?]{
|
||||
|
||||
Registers a daily rotating file destination. The current day's log is kept as
|
||||
plain text in @racket[filename]. When the date changes, the previous file is
|
||||
compressed with gzip and stored as
|
||||
@tt{filename.YYYY-MM-DD.gz}.
|
||||
|
||||
@racket[retention-days] is the total number of calendar days retained, including
|
||||
the current uncompressed day. With the default value of @racket[7], the current
|
||||
day and at most the previous six calendar days are retained. Compressed files
|
||||
older than that period are removed.
|
||||
|
||||
If @racket[filename] already exists when rotating logging is enabled, a file
|
||||
modified today is appended to. An older file is first archived under its last
|
||||
modification date. This makes restarting an application on the same day preserve
|
||||
the current day's log.
|
||||
|
||||
For example:
|
||||
|
||||
@racketblock[
|
||||
(sl-log-to-rotating-file "application.log")
|
||||
(sl-log-to-rotating-file "application.log" 14)
|
||||
]
|
||||
}
|
||||
|
||||
@defproc[(sl-log-to-file&display [filename path-string?]) void?]{
|
||||
|
||||
Enables both the display and file destinations.
|
||||
|
||||
Reference in New Issue
Block a user