本文整理汇总了Python中twisted.python.logfile.LogFile.flush方法的典型用法代码示例。如果您正苦于以下问题:Python LogFile.flush方法的具体用法?Python LogFile.flush怎么用?Python LogFile.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.logfile.LogFile
的用法示例。
在下文中一共展示了LogFile.flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DummyLogFile
# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import flush [as 别名]
class DummyLogFile(object):
'''Dummy log file used for testing.'''
def __init__(
self, worker_id, directory, rotateLength, maxRotatedFiles):
self.worker_id = worker_id
self.directory = directory
self.rotateLength = rotateLength
self.maxRotatedFiles = maxRotatedFiles
self.closed_count = 0
self.logfile = LogFile(
worker_id, directory, rotateLength=rotateLength,
maxRotatedFiles=maxRotatedFiles)
self.path = self.logfile.path
@property
def logs(self):
reader = self.logfile.getCurrentLog()
logs = []
lines = reader.readLines()
while lines:
logs.extend(lines)
lines = reader.readLines()
return logs
def write(self, data):
self.logfile.write(data)
self.logfile.flush()
def close(self):
self.closed_count += 1
def listLogs(self):
return []
示例2: emmit
# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import flush [as 别名]
def emmit(self, event):
if event.get("isDebug", False) and is_production():
return # Don't log debug messages in production.
location, prefix, log_time, log_time_str, entry_text = self.parse_from(event)
folder, name = build_file(self.folder, location, self.extension)
try:
log = LogFile(name, folder)
log.write("%s %s\n\t%s\n" % (prefix, log_time_str, entry_text.replace("\n", "\n\t\t")))
log.flush()
log.close()
finally:
if event.get("transmit", False) and not event.get("isDebug", False):
self.service.write_entry(location, log_time, entry_text)
示例3: receive_logs
# 需要导入模块: from twisted.python.logfile import LogFile [as 别名]
# 或者: from twisted.python.logfile.LogFile import flush [as 别名]
def receive_logs(self, logs, transport):
client_mac = self.__stations[transport.client].mac;
client_mac = client_mac.translate(None, ":|/\\")
files = {}
for time, location, msg in logs:
if location in files:
log_file = files[location]
else:
loc = [client_mac] + list(location)
folder, name = build_file(self.__output_folder, loc, self.__extension)
log_file = LogFile(name, folder)
files[location] = log_file
log_time_str = strftime("%Y-%m-%d %H:%M:%S:%f", gmtime(time))
log_file.write(">%s\n\t%s\n" % (log_time_str, msg.replace("\n", "\n\t\t")))
# Now close those files
for log_file in files.itervalues():
log_file.flush()
log_file.close()
return {"accepted": True}