Skip to content

Commit 62437a2

Browse files
authored
bpo-43047: logging.config formatters documentation update (GH-24358)
The documentation for some parts of the logging.config formatters has fallen behind the code. For example, the dictionary-schema section does not list the "class" attribute, however it is discussed in the file/ini discussion; and neither references the style argument which has been added. This modifies the dictionary-schema formatters documentation to list the keys available and overall makes it clearer these are passed to create a logging.Formatter object. The logging.Formatter documentation describes the default values of format/datefmt and the various formatting options. Since we have now more clearly described how the configuration is created via this type of object, we remove the discussion in this document to avoid duplication and rely on users reading the referenced logging.Formatter documenation directly for such details. Instead of duplicating the discussion for the two config types, the file/ini section is modified to link back to the dictionary-schema discussion, making it clear the same arguments are accepted. Automerge-Triggered-By: GH:vsajip
1 parent 5c5a938 commit 62437a2

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

Doc/library/logging.config.rst

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,29 @@ custom instantiation is required. If so, the mechanism described in
218218
:ref:`logging-config-dict-userdef` below is used to create an instance;
219219
otherwise, the context is used to determine what to instantiate.
220220

221+
.. _logging-config-dictschema-formatters:
222+
221223
* *formatters* - the corresponding value will be a dict in which each
222224
key is a formatter id and each value is a dict describing how to
223225
configure the corresponding :class:`~logging.Formatter` instance.
224226

225-
The configuring dict is searched for keys ``format`` and ``datefmt``
226-
(with defaults of ``None``) and these are used to construct a
227-
:class:`~logging.Formatter` instance.
227+
The configuring dict is searched for the following optional keys
228+
which correspond to the arguments passed to create a
229+
:class:`~logging.Formatter` object:
230+
231+
* ``format``
232+
* ``datefmt``
233+
* ``style``
234+
* ``validate`` (since version >=3.8)
228235

229-
.. versionchanged:: 3.8
230-
a ``validate`` key (with default of ``True``) can be added into
231-
the ``formatters`` section of the configuring dict, this is to
232-
validate the format.
236+
An optional ``class`` key indicates the name of the formatter's
237+
class (as a dotted module and class name). The instantiation
238+
arguments are as for :class:`~logging.Formatter`, thus this key is
239+
most useful for instantiating a customised subclass of
240+
:class:`~logging.Formatter`. For example, the alternative class
241+
might present exception tracebacks in an expanded or condensed
242+
format. If your formatter requires different or extra configuration
243+
keys, you should use :ref:`logging-config-dict-userdef`.
233244

234245
* *filters* - the corresponding value will be a dict in which each key
235246
is a filter id and each value is a dict describing how to configure
@@ -791,20 +802,13 @@ Sections which specify formatter configuration are typified by the following.
791802
[formatter_form01]
792803
format=F1 %(asctime)s %(levelname)s %(message)s
793804
datefmt=
805+
style='%'
806+
validate=True
794807
class=logging.Formatter
795808
796-
The ``format`` entry is the overall format string, and the ``datefmt`` entry is
797-
the :func:`strftime`\ -compatible date/time format string. If empty, the
798-
package substitutes something which is almost equivalent to specifying the date
799-
format string ``'%Y-%m-%d %H:%M:%S'``. This format also specifies milliseconds,
800-
which are appended to the result of using the above format string, with a comma
801-
separator. An example time in this format is ``2003-01-23 00:29:50,411``.
802-
803-
The ``class`` entry is optional. It indicates the name of the formatter's class
804-
(as a dotted module and class name.) This option is useful for instantiating a
805-
:class:`~logging.Formatter` subclass. Subclasses of
806-
:class:`~logging.Formatter` can present exception tracebacks in an expanded or
807-
condensed format.
809+
The arguments for the formatter configuration are the same as the keys
810+
in the dictionary schema :ref:`formatters section
811+
<logging-config-dictschema-formatters>`.
808812

809813
.. note::
810814

0 commit comments

Comments
 (0)