Skip to content

Commit d5e0786

Browse files
authored
gh-88287: Add BufferingFormatter documentation. (GH-96608)
1 parent 4e4bfff commit d5e0786

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
@@ -662,6 +662,35 @@ Formatter Objects
662662
:func:`traceback.print_stack`, but with the last newline removed) as a
663663
string. This default implementation just returns the input value.
664664

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

667696
Filter Objects

0 commit comments

Comments
 (0)