本文整理汇总了Python中twisted.python.logfile.DailyLogFile.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DailyLogFile.flush方法的具体用法?Python DailyLogFile.flush怎么用?Python DailyLogFile.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.logfile.DailyLogFile
的用法示例。
在下文中一共展示了DailyLogFile.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PrintLogThread
# 需要导入模块: from twisted.python.logfile import DailyLogFile [as 别名]
# 或者: from twisted.python.logfile.DailyLogFile import flush [as 别名]
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()
示例2: ChatLogger
# 需要导入模块: from twisted.python.logfile import DailyLogFile [as 别名]
# 或者: from twisted.python.logfile.DailyLogFile import flush [as 别名]
class ChatLogger(object):
def __init__(self, logfile, path):
self.log = DailyLogFile(logfile, path)
date = datetime.now().strftime('%a %b %d %H:%M %Y')
self.log.write('--- Log opened: %s\n' % (date, ))
def write_line(self, line):
self.log.write(datetime.now().strftime('%H:%M '))
if isinstance(line, unicode):
line = line.encode('utf-8')
self.log.write(line)
self.log.write('\n')
self.log.flush()
def action(self, nick, message):
self.write_line(' * %s %s' % (nick, message))
def message(self, nick, message):
self.write_line('<%s> %s' % (nick, message))