bpo-40884: Added defaults parameter for logging.Formatter (GH-20668)



Docs and tests are underway.

Automerge-Triggered-By: @vsajip
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 @@
 :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 @@
    :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 @@
       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