Steve R. Hastings <[email protected]> added the comment:
I just reviewed the Python 3.6 logging code. Unless I am mistaken, it still
has the limitation that when a logging file is active for writing log events,
that file always has the same filename (self.baseFilename). Did I overlook
anything?
At rotation time, the self.namer() function is called, and it could implement
any desired naming scheme. However, its only argument is the already templated
filename.
So if I needed to implement logging with a filename of: foo-YYYYmmdd.log at all
times, how would I get the current file (the open file to which log events are
being written) to have that pattern of name?
And if I needed to write a self.namer() function to rename to that standard, is
this the recommended approach?
# for daily rotations, the built-in template is: "%Y-%m-%d"
def namer(self, filename):
# filename will look like: foo-YYYY-mm-dd.log
year = filename[-14:-10]
month = filename[-9:-7]
day = filename[-6:-4]
base = filename[:-14]
new_filename = base + year + month + day + ".log"
return new_filename # will look like: foo-YYYYmmdd.log
The logging event that triggered the rollover is not passed to the namer()
function, just the templated default filename.
In my opinion, it is more convenient for the user to simply specify the desired
format using template codes, such as:
handler = TimedRotatingFileHandler("foo", suffix="-%Y%m%d", when="D")
Also, unless I have overlooked something, using the self.namer() function to
implement a custom naming scheme completely disables the code that
automatically deletes the oldest backup files when backupCount is specified.
The getBackupFilesToDelete() function uses the self.extMatch value (a
pre-compiled regular expression) to find files to delete; with a custom naming
scheme, the files will not match the pattern. Therefore users with a custom
naming scheme would have to implement some external solution to deleting old
files after log rotation.
The code I am proposing to donate to Python automatically builds a suitable
regular expression for the self.extMatch member variable, based on the user's
specified format string. I believe this is an advantage for the code I propose
to donate.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33506>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com