我目前在为我的应用程序管理旋转日志文件时遇到了麻烦,但是日志变得越来越大,我想考虑在它们旋转时压缩它们。
我快速浏览了扭曲的文档,但看不出如何使用 DailyLogFile 执行此操作类。
我的日志设置是:
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)
有人知道怎么做吗?
请您参考如下方法:
您可以继承DailyLogFile 并重载rotate 方法:
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
