@@ -661,6 +661,76 @@ it with :func:`staticmethod`. For example::
661661You don't need to wrap with :func: `staticmethod ` if you're setting the import
662662callable on a configurator *instance *.
663663
664+ .. _configure-queue :
665+
666+ Configuring QueueHandler and QueueListener
667+ """"""""""""""""""""""""""""""""""""""""""
668+
669+ If you want to configure a :class: `~logging.handlers.QueueHandler `, noting that this
670+ is normally used in conjunction with a :class: `~logging.handlers.QueueListener `, you
671+ can configure both together. After the configuration, the ``QueueListener `` instance
672+ will be available as the :attr: `~logging.handlers.QueueHandler.listener ` attribute of
673+ the created handler, and that in turn will be available to you using
674+ :func: `~logging.getHandlerByName ` and passing the name you have used for the
675+ ``QueueHandler `` in your configuration. The dictionary schema for configuring the pair
676+ is shown in the example YAML snippet below.
677+
678+ .. code-block :: yaml
679+
680+ handlers :
681+ qhand :
682+ class : logging.handlers.QueueHandler
683+ queue : my.module.queue_factory
684+ listener : my.package.CustomListener
685+ handlers :
686+ - hand_name_1
687+ - hand_name_2
688+ ...
689+
690+ The ``queue `` and ``listener `` keys are optional.
691+
692+ If the ``queue `` key is present, the corresponding value can be one of the following:
693+
694+ * An actual instance of :class: `queue.Queue ` or a subclass thereof. This is of course
695+ only possible if you are constructing or modifying the configuration dictionary in
696+ code.
697+
698+ * A string that resolves to a callable which, when called with no arguments, returns
699+ the :class: `queue.Queue ` instance to use. That callable could be a
700+ :class: `queue.Queue ` subclass or a function which returns a suitable queue instance,
701+ such as ``my.module.queue_factory() ``.
702+
703+ * A dict with a ``'()' `` key which is constructed in the usual way as discussed in
704+ :ref: `logging-config-dict-userdef `. The result of this construction should be a
705+ :class: `queue.Queue ` instance.
706+
707+ If the ``queue `` key is absent, a standard unbounded :class: `queue.Queue ` instance is
708+ created and used.
709+
710+ If the ``listener `` key is present, the corresponding value can be one of the following:
711+
712+ * A subclass of :class: `logging.handlers.QueueListener `. This is of course only
713+ possible if you are constructing or modifying the configuration dictionary in
714+ code.
715+
716+ * A string which resolves to a class which is a subclass of ``QueueListener ``, such as
717+ ``'my.package.CustomListener' ``.
718+
719+ * A dict with a ``'()' `` key which is constructed in the usual way as discussed in
720+ :ref: `logging-config-dict-userdef `. The result of this construction should be a
721+ callable with the same signature as the ``QueueListener `` initializer.
722+
723+ If the ``listener `` key is absent, :class: `logging.handlers.QueueListener ` is used.
724+
725+ The values under the ``handlers `` key are the names of other handlers in the
726+ configuration (not shown in the above snippet) which will be passed to the queue
727+ listener.
728+
729+ Any custom queue handler and listener classes will need to be defined with the same
730+ initialization signatures as :class: `~logging.handlers.QueueHandler ` and
731+ :class: `~logging.handlers.QueueListener `.
732+
733+ .. versionadded :: 3.12
664734
665735.. _logging-config-fileformat :
666736
0 commit comments