Rotating log file with retention

This commit is contained in:
2026-08-30 09:28:58 +02:00
parent f88ee4951e
commit 8810edf801
5 changed files with 202 additions and 3 deletions
+28
View File
@@ -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.