Search code examples
pythonloggingtwisted

Twistedmatrix, rotate log on a weekly basis and customizing name of the log


what should be the better way to use Python twistedmatrix log file, and customize it so that it can be : - rotating on a weekly basis (sunday) - with a custom naming convention (replace the current date _underscore glued that can be seen in the DailyLogFile with something like myfile.yyyymmdd.log or so)

shoud it be by writing my own/subclassing in the same way as class DailyLogFile(BaseLogFile): ?

i have seen that some consider logrotate from linux command, but i wanted to go with a python twistedmatrix solution. (but maybe are there some trouble that i dot have guessed ?)

best regards


Solution

  • You can definitely do this with Twisted's logging system. You're on the right track by looking at DailyLogFile.

    However, consider that the best solution might involve idiomatically integrating with the target deployment platform. If the convention on the platform is for applications to manage their own log files, then I'd say you're on the right track.

    If, instead, the convention is for applications to run under a manager like launchd, then you may want to consider that approach instead. If all deployed software follows the same local conventions, then the system admin has an easier time managing everything correctly.