QueueLogger
是一个用于后台日志记录的工具。它用于将日志消息存储在一个队列中,以便在后台进行处理和记录。
下面是他的代码
# Code to implement asynchronous logging from a background thread
#
# Copyright (C) 2016-2019 Kevin O'Connor <[email protected]>
#
# 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