[Python-checkins] gh-88287: Add BufferingFormatter documentation. (GH-96608)

vsajip webhook-mailer at python.org
Thu Sep 8 03:22:49 EDT 2022


https://github.com/python/cpython/commit/d5e07862ec8b6368c98f649d6c6091b06cdae468
commit: d5e07862ec8b6368c98f649d6c6091b06cdae468
branch: main
author: Vinay Sajip <vinay_sajip at yahoo.co.uk>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-09-08T08:22:33+01:00
summary:

gh-88287: Add BufferingFormatter documentation. (GH-96608)

files:
M Doc/library/logging.rst

diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst
index c3806b6f5bf..8793627e119 100644
--- a/Doc/library/logging.rst
+++ b/Doc/library/logging.rst
@@ -662,6 +662,35 @@ Formatter Objects
       :func:`traceback.print_stack`, but with the last newline removed) as a
       string. This default implementation just returns the input value.
 
+.. class:: BufferingFormatter(linefmt=None)
+
+   A base formatter class suitable for subclassing when you want to format a
+   number of records. You can pass a :class:`Formatter` instance which you want
+   to use to format each line (that corresponds to a single record). If not
+   specified, the default formatter (which just outputs the event message) is
+   used as the line formatter.
+
+   .. method:: formatHeader(records)
+
+      Return a header for a list of *records*. The base implementation just
+      returns the empty string. You will need to override this method if you
+      want specific behaviour, e.g. to show the count of records, a title or a
+      separator line.
+
+   .. method:: formatFooter(records)
+
+      Return a footer for a list of *records*. The base implementation just
+      returns the empty string. You will need to override this method if you
+      want specific behaviour, e.g. to show the count of records or a separator
+      line.
+
+   .. method:: format(records)
+
+      Return formatted text for a list of *records*. The base implementation
+      just returns the empty string if there are no records; otherwise, it
+      returns the concatenation of the header, each record formatted with the
+      line formatter, and the footer.
+
 .. _filter:
 
 Filter Objects



More information about the Python-checkins mailing list