diff options
author | Bar Harel <bzvi7919@gmail.com> | 2020-06-18 14:18:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 14:18:58 (GMT) |
commit | 8f192d12af82c4dc40730bf59814f6a68f68f950 (patch) | |
tree | a7666641789d3aca6f2323b7fc6f0d642eac250b /Doc/library | |
parent | ddbeb2f3e02a510c5784ffd74c5e09e8c70b5881 (diff) | |
download | cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.zip cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.tar.gz cpython-8f192d12af82c4dc40730bf59814f6a68f68f950.tar.bz2 |
bpo-40884: Added defaults parameter for logging.Formatter (GH-20668)
Docs and tests are underway.
Automerge-Triggered-By: @vsajip
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/logging.rst | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst index 7267f81..3ff67f7 100644 --- a/Doc/library/logging.rst +++ b/Doc/library/logging.rst @@ -529,7 +529,8 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on :ref:`logrecord-attributes`. -.. class:: Formatter(fmt=None, datefmt=None, style='%', validate=True) +.. class:: Formatter(fmt=None, datefmt=None, style='%', validate=True, *, + defaults=None) Returns a new instance of the :class:`Formatter` class. The instance is initialized with a format string for the message as a whole, as well as a @@ -545,6 +546,10 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on :ref:`formatting-styles` for more information on using {- and $-formatting for log messages. + The *defaults* parameter can be a dictionary with default values to use in + custom fields. For example: + ``logging.Formatter('%(ip)s %(message)s', defaults={"ip": None})`` + .. versionchanged:: 3.2 The *style* parameter was added. @@ -553,6 +558,9 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on will raise a ``ValueError``. For example: ``logging.Formatter('%(asctime)s - %(message)s', style='{')``. + .. versionchanged:: 3.10 + The *defaults* parameter was added. + .. method:: format(record) The record's attribute dictionary is used as the operand to a string |