当前位置: 首页>>代码示例>>Python>>正文


Python DailyLogFile.flush方法代码示例

本文整理汇总了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()
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:37,代码来源:output.py

示例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))
开发者ID:Trundle,项目名称:kitbot,代码行数:21,代码来源:bot.py


注:本文中的twisted.python.logfile.DailyLogFile.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。