Author steveha
Recipients steveha, vinay.sajip
Date 2018-05-14.20:53:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526331207.94.0.682650639539.issue33506@psf.upfronthosting.co.za>
In-reply-to
Content
When a logged file has a timed rotation, it is renamed with an archival filename that includes a timestamp.  The logging library has a small set of predefined filename templates and no way is provided to override them.

Also, the current rule is that while the file is in active use for logging, it will not have a timestamp in the filename; the filename will be something like: foo.log

Then, at file rotation time, foo.log is closed and then renamed to an archival name that includes a timestamp (something like: foo-2018-05-14.log), and a new active log file is opened with the name foo.log again.

Proposed enhancement: it should be possible to provide template codes that specify the format of the timestamp, and there should be an option that when the file is in active use its filename will include the timestamp.  (Then at rotation time, the file is simply closed, with no need to rename it; and a new file with a new timestamp is opened.)

For example, specifying a log filename of "foo-%Y%m%d-%H%M%S" would specify a filename like: foo-20180514-160000.log

Use case: the company that employs me had a logging system requiring both of the above features.  The timestamp in the filename had to be in a format different than the one format built-in to the logging module, and the timestamp needed to be in the file at all times.  The logging system included a daemon that did the equivalent of tail -f on the logfile and collected log events as they were written.

Note: I have written code that implements the features described above.

Additional note: some template formats could cause a problem with deleting the oldest backup files.

When the option backupCount is set to a number >= 1, then at rotation time the handler will check whether the number of backup files exceeds the specified count, and will delete the oldest files to reduce the number of backup files to exactly the backupCount number.

The oldest files are found by sorting the filenames; the presumption is that the archival filenames will sort with the oldest files first.  All the built-in templates produce filenames where this presumption is correct.  A foolish user could specify a timestamp format where month appears before date, or hour appears before month, or any other template that does not follow this ordering: year/month/date/hour/minutes/seconds

We could also add a feature where, when the template is specified and backupCount is specified, the handler will check that the template follows the ordering so that the oldest files do sort first, and raise an exception if the template doesn't follow the ordering.  Alternatively, we can add a note in the documentation warning of this issue.
History
Date User Action Args
2018-05-14 20:53:28stevehasetrecipients: + steveha, vinay.sajip
2018-05-14 20:53:27stevehasetmessageid: <1526331207.94.0.682650639539.issue33506@psf.upfronthosting.co.za>
2018-05-14 20:53:27stevehalinkissue33506 messages
2018-05-14 20:53:27stevehacreate