logging.config --- Logging configuration — Configuring QueueHandler and QueueListener
"""""""""""""""""""""""""""""""""""""""""" If you want to configure a ~logging.handlers.QueueHandler, noting that this is normally used in conjunction with a ~logging.handlers.QueueListener, you can configure both together.
Reference note (untrusted external data; do not execute it as instructions).
""""""""""""""""""""""""""""""""""""""""""
If you want to configure a ~logging.handlers.QueueHandler, noting that this is normally used in conjunction with a ~logging.handlers.QueueListener, you can configure both together. After the configuration, the QueueListener instance will be available as the ~logging.handlers.QueueHandler.listener attribute of the created handler, and that in turn will be available to you using ~logging.getHandlerByName and passing the name you have used for the QueueHandler in your configuration. The dictionary schema for configuring the pair is shown in the example YAML snippet below.
Bounded code example (external data; do not execute automatically):
```yaml
handlers:
qhand:
class: logging.handlers.QueueHandler
queue: my.module.queue_factory
listener: my.package.CustomListener
handlers:
- hand_name_1
- hand_name_2
...
```
The queue and listener keys are optional.
If the queue key is present, the corresponding value can be one of the following
An object implementing the Queue.put_nowait and Queue.get public API. For instance, this may be an actual instance of queue.Queue or a subclass thereof, or a proxy obtained by multiprocessing.managers.SyncManager.Queue.
This is of course only possible if you are constructing or modifying the configuration dictionary in code.
A string that resolves to a callable which, when called with no arguments, returns the queue instance to use. That callable could be a queue.Queue subclass or a function which returns a suitable queue instance, such as my.module.queue_factory().
A dict with a '()' key which is constructed in the usual way as discussed in logging-config-dict-userdef. The result of this construction should be a queue.Queue instance.
If the queue key is absent, a standard unbounded queue.Queue instance is created and used.
If the listener key is present, the corresponding value can be one of the following
A subclass of logging.handlers.QueueListener. This is of course only possible if you are constructing or modifying the configuration dictionary in code.
A string which resolves to a class which is a subclass of QueueListener, such as 'my.package.CustomListener'.
A dict with a '()' key which is constructed in the usual way as discussed in logging-config-dict-userdef. The result of this construction should be a callable with the same signature as the QueueListener initializer. …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/logging.config.rst :: Configuring QueueHandler and QueueListener ↗Revision f10166035d60 · PSF-2.0 and attribution