我有一个 Python 多处理应用程序,我想向其中添加一些日志记录功能。Python日志记录手册建议使用Queue. 每个进程都会通过 向其中放入日志记录,QueueHandler并且侦听器进程将通过预定义的 处理这些记录Handler。
以下是 Python 日志记录手册提供的示例:
# You'll need these imports in your own code
import logging
import logging.handlers
import multiprocessing
# Next two import lines for this demo only
from random import choice, random
import time
#
# Because you'll want to define the logging configurations for listener and workers, the
# listener and worker process functions take a configurer parameter which is a callable
# for configuring …Run Code Online (Sandbox Code Playgroud)