本文整理汇总了Python中twisted.python.logfile.DailyLogFile.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python DailyLogFile.rotate方法的具体用法?Python DailyLogFile.rotate怎么用?Python DailyLogFile.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.logfile.DailyLogFile
的用法示例。
在下文中一共展示了DailyLogFile.rotate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotate
# 需要导入模块: from twisted.python.logfile import DailyLogFile [as 别名]
# 或者: from twisted.python.logfile.DailyLogFile import rotate [as 别名]
def rotate(self):
"""Rotate the current logfile.
Also remove extra entries and compress the last ones.
"""
# Rotate the log daily.
DailyLogFile.rotate(self)
# Remove 'extra' rotated log files.
logs = self.listLogs()
for log_path in logs[self.maxRotatedFiles:]:
os.remove(log_path)
# Refresh the list of existing rotated logs
logs = self.listLogs()
# Skip compressing if there are no files to be compressed.
if len(logs) <= self.compressLast:
return
# Compress last log files.
for log_path in logs[-self.compressLast:]:
# Skip already compressed files.
if log_path.endswith('bz2'):
continue
self._compressFile(log_path)
示例2: rotate
# 需要导入模块: from twisted.python.logfile import DailyLogFile [as 别名]
# 或者: from twisted.python.logfile.DailyLogFile import rotate [as 别名]
def rotate(self):
DailyLogFile.rotate(self)
dir = os.path.dirname(self.path)
files = os.listdir(dir)
for file in files:
if file.startswith("honeypy.log."):
os.remove(os.path.join(dir, file))
示例3: rotate
# 需要导入模块: from twisted.python.logfile import DailyLogFile [as 别名]
# 或者: from twisted.python.logfile.DailyLogFile import rotate [as 别名]
def rotate(self):
"""
Rotate the file and create a new one.
If it's not possible to open new logfile, this will fail silently,
and continue logging to old logfile.
Old log files will be automatically purged.
"""
#daily rotation first
DailyLogFile.rotate(self)
if not self.maxRotatedFiles:
return
if not (os.access(self.directory, os.W_OK) and os.access(self.path, os.W_OK)):
return
logs = self.listLogs()
while len(logs) >= self.maxRotatedFiles:
l = logs.pop(0)
#this should never match, but just make sure
if l.endswith('log'): continue
self.notification('deleting %s' % l)
os.remove(l)