asleea asleea - 1 year ago 76
Python Question

Naming rotating log files specific name in Python

I want to name rotating log files as I want.

For example, if I use RotatingFileHandler, It separates log file when it reaches to specific file size naming

log file name + extension numbering
, like below.

filename.log #first log file
filename.log.1 #rotating log file1
filename.log.2 #rotating log file2

However, I want log handler to name them every time it is created at.
For example.

09-01-12-20.log #first log file
09-01-12-43.log #rotating log file1
09-01-15-00.log #rotating log file2

How can I do this ?


I am not asking how to create and name a file.

I want to facailate python
package doing something like inheriting and overriding

Answer Source

I fix RotatingFileHandler of python logging handler.

RotatingFileHandler has self.baseFilename value, the handler will use self.baseFilename to create logFile.(when it creates file first or when rollover happens)

self.shouldRollover() method, It checks if the handler should rollover logfile or not.

If this method return 1, it means rollover should happen or return 0.

By overriding them, I define when this handler makes rollover and which name should be used for new log file by rollover.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download