栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

python日志记录会刷新每个日志吗?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python日志记录会刷新每个日志吗?

是的,它会在每次调用时刷新输出。您可以在的源代码中看到

StreamHandler

def flush(self):    """    Flushes the stream.    """    self.acquire()    try:        if self.stream and hasattr(self.stream, "flush"): self.stream.flush()    finally:        self.release()def emit(self, record):    """    Emit a record.    If a formatter is specified, it is used to format the record.    The record is then written to the stream with a trailing newline.  If    exception information is present, it is formatted using    traceback.print_exception and appended to the stream.  If the stream    has an 'encoding' attribute, it is used to determine how to do the    output to the stream.    """    try:        msg = self.format(record)        stream = self.stream        stream.write(msg)        stream.write(self.terminator)        self.flush()   # <---    except (KeyboardInterrupt, SystemExit): #pragma: no cover        raise    except:        self.handleError(record)

我真的不会介意日志记录的性能,至少在分析和发现它是瓶颈之前不会。无论如何,您始终可以创建一个在每次调用时都

Handler
不会执行的子类(即使如果发生严重异常/解释器崩溃,也可能会丢失大量日志)。
flush``emit



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/641293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号