#🔒 Python <3.12 How to prevent log record broadcast to all queue handlers by a single queue listener

5 messages · Page 1 of 1 (latest)

flint topaz
#

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.

  1. https://docs.python.org/3.11/howto/logging-cookbook.html#dealing-with-handlers-that-block
  2. 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.

GitHub

The code for for the medium article "How to use Python logging QueueHandler with dictConfig" - rob-blackbourn/medium-queue-logging

prisma wolfBOT
#

@flint topaz

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

prisma wolfBOT
prisma wolfBOT
#

@flint topaz

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.