Reputation: 10781
I currently have twisted managing rotating the log files for my application, however the logs are becoming large and I'd like to look at compressing them when they rotate.
I've done a quick look through the twisted docs and don't see how I can do this with the DailyLogFile
class.
My setup for logging is:
from twisted.python.log import ILogObserver, FileLogObserver
from twisted.python.logfile import DailyLogFile
...
"Setup the logging"
logPath = os.getcwd() + "/logs/"
logFile = DailyLogFile("lazarus.log", logPath, defaultMode=0644)
application.setComponent(ILogObserver, FileLogObserver(logFile).emit)
Does anyone know how to do this?
Upvotes: 2
Views: 652
Reputation: 16327
You could subclass DailyLogFile
and overload the rotate
method:
class DailyCompressedLogFile(DailyLogFile):
def rotate(self):
super(DailyCompressedLogFile, self).rotate()
newpath = "%s.%s" % (self.path, self.suffix(self.lastDate))
if os.path.exists(newpath):
# compress newpath here
Upvotes: 1