I am using Python 3.11 now, to develop a web application that supports asynchronous I/O and involves logging. I understand Python's built-in logging's QueueHandler and QueueListener is a good way to go.
The minimal example of my implementation is in the attachment (maybe it is little bit of lengthy, and it couldn't show up directly as follows). After I executed python example.py , I can see six lines of log records in console stdout and those three log files, i.e., server.log, access.log and external.log . However, my demand is to separate (or let's say, route) each handlers' log record to their own log files respectively via Queue Handler working with Queue Listener even if log records have the same logging level.
My references are as follows.
- https://docs.python.org/3.11/howto/logging-cookbook.html#dealing-with-handlers-that-block
- https://github.com/rob-blackbourn/medium-queue-logging
I hope I explained my problems clearly. I am glad to provide more information if needed. Thank you in advance.
The code for for the medium article "How to use Python logging QueueHandler with dictConfig" - rob-blackbourn/medium-queue-logging