New submission from Steve R. Hastings <stev...@users.sourceforge.net>:

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.

----------
components: Library (Lib)
messages: 316573
nosy: steveha, vinay.sajip
priority: normal
severity: normal
status: open
title: [logging] template for filename timestamps
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33506>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to