赞
踩
QueueLogger
是一个用于后台日志记录的工具。它用于将日志消息存储在一个队列中,以便在后台进行处理和记录。
下面是他的代码
- # Code to implement asynchronous logging from a background thread
- #
- # Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
- #
- # This file may be distributed under the terms of the GNU GPLv3 license.
- import logging, logging.handlers, threading, queue, time
-
- # Class to forward all messages through a queue to a background thread
- class QueueHandler(logging.Handler):
- def __init__(self, queue):
- logging.Handler.__init__(self)
- self.queue = queue
- def emit(self, record):
- try:
- self.format(record)
- record.msg = record.message
- record.args = None
- record.exc_info = None
- self.queue.put_nowait(record)
- except Exception:
- self.handleError(record)
-
- # Class to poll a queue in a background thread and log each message
- class QueueListener(logging.handler
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。