Skip to content

Commit a3d5ecb

Browse files
[3.11] gh-88287: Add BufferingFormatter documentation. (GH-96608) (GH-96675)
1 parent ffafa9b commit a3d5ecb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Doc/library/logging.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,35 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on
652652
:func:`traceback.print_stack`, but with the last newline removed) as a
653653
string. This default implementation just returns the input value.
654654

655+
.. class:: BufferingFormatter(linefmt=None)
656+
657+
A base formatter class suitable for subclassing when you want to format a
658+
number of records. You can pass a :class:`Formatter` instance which you want
659+
to use to format each line (that corresponds to a single record). If not
660+
specified, the default formatter (which just outputs the event message) is
661+
used as the line formatter.
662+
663+
.. method:: formatHeader(records)
664+
665+
Return a header for a list of *records*. The base implementation just
666+
returns the empty string. You will need to override this method if you
667+
want specific behaviour, e.g. to show the count of records, a title or a
668+
separator line.
669+
670+
.. method:: formatFooter(records)
671+
672+
Return a footer for a list of *records*. The base implementation just
673+
returns the empty string. You will need to override this method if you
674+
want specific behaviour, e.g. to show the count of records or a separator
675+
line.
676+
677+
.. method:: format(records)
678+
679+
Return formatted text for a list of *records*. The base implementation
680+
just returns the empty string if there are no records; otherwise, it
681+
returns the concatenation of the header, each record formatted with the
682+
line formatter, and the footer.
683+
655684
.. _filter:
656685

657686
Filter Objects

0 commit comments

Comments
 (0)