本文整理汇总了Python中twisted.python.logfile.DailyLogFile类的典型用法代码示例。如果您正苦于以下问题:Python DailyLogFile类的具体用法?Python DailyLogFile怎么用?Python DailyLogFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DailyLogFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rotate
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
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: PrintLogThread
class PrintLogThread(threading.Thread):
'''
All file printing access from one thread.
Receives information when its placed on the passed queue.
Called from one location: Output.handlePrint.
Does not close the file: this happens in Output.endLogging. This
simplifies the operation of this class, since it only has to concern
itself with the queue.
The path must exist before DailyLog runs for the first time.
'''
def __init__(self, path, queue, name):
threading.Thread.__init__(self)
self.queue = queue
self.writer = DailyLogFile(name, path)
# Don't want this to float around if the rest of the system goes down
self.setDaemon(True)
def run(self):
while True:
result = self.queue.get(block=True)
try:
writable = json.dumps(result)
self.writer.write(writable + '\n')
self.writer.flush()
except:
pass
self.queue.task_done()
示例4: makeService
def makeService(_config):
global config
config = _config
if config['logpath'] != None:
logFilePath = os.path.abspath(config['logpath'])
logFile = DailyLogFile.fromFullPath(logFilePath)
else:
logFile = sys.stdout
log.startLogging(logFile)
lumenService = service.MultiService()
# Bayeux Service
import bayeux
bayeuxFactory = bayeux.BayeuxServerFactory()
bayeuxService = internet.TCPServer(config['port'], bayeuxFactory)
bayeuxService.setServiceParent(lumenService)
# WebConsole Service
import webconsole
site = server.Site(webconsole.WebConsole())
webConsoleService = internet.TCPServer(config['webport'], site)
webConsoleService.setServiceParent(lumenService)
application = service.Application("lumen")
lumenService.setServiceParent(application)
return lumenService
示例5: write
def write(self, data):
if not self.enableRotation:
if not os.path.exists(self.path):
self.reopen()
else:
path_stat = os.stat(self.path)
fd_stat = os.fstat(self._file.fileno())
if not (path_stat.st_ino == fd_stat.st_ino and path_stat.st_dev == fd_stat.st_dev):
self.reopen()
DailyLogFile.write(self, data)
示例6: __init__
def __init__(self, name, directory, defaultMode=None,
maxRotatedFiles=None, compressLast=None):
DailyLogFile.__init__(self, name, directory, defaultMode)
if maxRotatedFiles is not None:
self.maxRotatedFiles = int(maxRotatedFiles)
if compressLast is not None:
self.compressLast = int(compressLast)
assert self.compressLast <= self.maxRotatedFiles, (
"Only %d rotate files are kept, cannot compress %d"
% (self.maxRotatedFiles, self.compressLast))
示例7: init_logging
def init_logging(logdir, logname):
if DEBUG_LEVEL > 0:
log.startLogging(sys.stdout)
if not os.path.exists(logdir):
os.makedirs(logdir)
logfile = get_path(os.path.join(logdir, logname))
log.startLogging(DailyLogFile.fromFullPath(logfile))
示例8: noiseControl
def noiseControl(options):
# terminal noise/info logic
# allows the specification of the log file location
if not options["loud"]:
log_path = options["log"]
log.startLogging(DailyLogFile.fromFullPath(log_path))
return None
示例9: make_logfile_observer
def make_logfile_observer(path, show_source=False):
"""
Make an observer that writes out to C{path}.
"""
from twisted.logger import FileLogObserver
from twisted.python.logfile import DailyLogFile
f = DailyLogFile.fromFullPath(path)
def _render(event):
if event.get("log_system", u"-") == u"-":
logSystem = u"{:<10} {:>6}".format("Controller", os.getpid())
else:
logSystem = event["log_system"]
if show_source and event.get("log_namespace") is not None:
logSystem += " " + event.get("cb_namespace", event.get("log_namespace", ''))
if event.get("log_format", None) is not None:
eventText = formatEvent(event)
else:
eventText = ""
if "log_failure" in event:
# This is a traceback. Print it.
eventText = eventText + event["log_failure"].getTraceback()
eventString = NOCOLOUR_FORMAT.format(
formatTime(event["log_time"]), logSystem, eventText) + os.linesep
return eventString
return FileLogObserver(f, _render)
示例10: __init__
def __init__(self):
try:
logfile = DailyLogFile.fromFullPath(cfg.logging.filename)
except AssertionError:
raise AssertionError("Assertion error attempting to open the log file: {0}. Does the directory exist?".format(cfg.logging.filename))
twistedlogger.startLogging(logfile, setStdout=False)
示例11: _createLogFile
def _createLogFile(self, uuid):
logDirPath = '{cwd}\\..\\logs\\aiprocesses'.format(cwd=os.getcwd())
if not os.path.exists(logDirPath):
os.mkdir(logDirPath)
logFilePath = '{dir}\\{uuid}.log'.format(dir=logDirPath, uuid=uuid)
log.startLogging(DailyLogFile.fromFullPath(logFilePath))
示例12: run_normal
def run_normal(self):
if self.debug:
log.startLogging(sys.stdout)
else:
log.startLogging(DailyLogFile.fromFullPath(self.logfile))
log.msg("portal server listen %s" % self.portal_host)
reactor.listenUDP(self.listen_port, self, interface=self.portal_host)
示例13: __init__
def __init__(self, path, queue, name):
threading.Thread.__init__(self)
self.queue = queue
self.writer = DailyLogFile(name, path)
# Don't want this to float around if the rest of the system goes down
self.setDaemon(True)
示例14: start_logging
def start_logging(opts):
from twisted.python import log
from twisted.python.logfile import DailyLogFile
if opts.logfile:
logfile = DailyLogFile.fromFullPath(opts.logfile)
else:
logfile = sys.stderr
log.startLogging(logfile)
示例15: __init__
def __init__(self, *args, **kwargs):
"""
Create a log file rotating on length.
@param name: file name.
@type name: C{str}
@param directory: path of the log file.
@type directory: C{str}
@param defaultMode: mode used to create the file.
@type defaultMode: C{int}
@param maxRotatedFiles: if not None, max number of log files the class
creates. Warning: it removes all log files above this number.
@type maxRotatedFiles: C{int}
"""
self.maxRotatedFiles = kwargs.pop('maxRotatedFiles', None)
DailyLogFile.__init__(self, *args, **kwargs)
self._logger = logWithContext(type='console')