On this page
logging.BufferingFormatter
Prev: logging.basicConfig | Up: logging | Next: logging.captureWarnings
Rel: logging.addLevelName, logging.basicConfig, logging.captureWarnings, logging.critical
Ref: docs.python.org — logging.BufferingFormatter
Tags: #public #python3 #stdlib #logging
Import
import logging
from logging import BufferingFormatter
Signature & Overview
logging.BufferingFormatter(linefmt=None)
A formatter suitable for formatting a number of records.
Methods & Attributes
BufferingFormatter.format(self, records)— Format the specified records and return the result as a string.BufferingFormatter.formatFooter(self, records)— Return the footer string for the specified records.BufferingFormatter.formatHeader(self, records)— Return the header string for the specified records.
Usage
import logging
class WrapFormatter(logging.BufferingFormatter):
def formatHeader(self, records): return "=== START ===\n"
def formatFooter(self, records): return "=== END ===\n"
fmt = WrapFormatter(logging.Formatter("%(levelname)s:%(message)s\n"))
rec = logging.LogRecord("app", logging.INFO, "", 1, "ok", (), None)
assert "=== START ===" in fmt.format([rec])
Gotchas
- Used with
MemoryHandler/ batch handlers: Formats a list ofLogRecordobjects at once with optional header and footer text.
REPL Inspect
from logging import BufferingFormatter
help(BufferingFormatter)
Linked from
- tuts/python3/stdlib_module/logging
- tuts/python3/stdlib_module/logging/addLevelName
- tuts/python3/stdlib_module/logging/basicConfig
- tuts/python3/stdlib_module/logging/captureWarnings
- tuts/python3/stdlib_module/logging/critical
- tuts/python3/stdlib_module/logging/debug
- tuts/python3/stdlib_module/logging/disable
- tuts/python3/stdlib_module/logging/error
- tuts/python3/stdlib_module/logging/exception
- tuts/python3/stdlib_module/logging/fatal
- tuts/python3/stdlib_module/logging/FileHandler
- tuts/python3/stdlib_module/logging/Filter
- tuts/python3/stdlib_module/logging/Formatter
- tuts/python3/stdlib_module/logging/getHandlerByName
- tuts/python3/stdlib_module/logging/getHandlerNames
- tuts/python3/stdlib_module/logging/getLevelName
- tuts/python3/stdlib_module/logging/getLevelNamesMapping
- tuts/python3/stdlib_module/logging/getLogger
- tuts/python3/stdlib_module/logging/getLoggerClass
- tuts/python3/stdlib_module/logging/getLogRecordFactory
- tuts/python3/stdlib_module/logging/Handler
- tuts/python3/stdlib_module/logging/info
- tuts/python3/stdlib_module/logging/log
- tuts/python3/stdlib_module/logging/Logger
- tuts/python3/stdlib_module/logging/LoggerAdapter
- tuts/python3/stdlib_module/logging/LogRecord
- tuts/python3/stdlib_module/logging/makeLogRecord
- tuts/python3/stdlib_module/logging/NullHandler
- tuts/python3/stdlib_module/logging/setLoggerClass
- tuts/python3/stdlib_module/logging/setLogRecordFactory
- tuts/python3/stdlib_module/logging/shutdown
- tuts/python3/stdlib_module/logging/StreamHandler
- tuts/python3/stdlib_module/logging/warn
- tuts/python3/stdlib_module/logging/warning
Related notes
- tuts/python3/stdlib_module/logging/addLevelName Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/basicConfig Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/captureWarnings Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/critical Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/logging/debug links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/disable links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/error links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/exception links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/fatal links to this page; shared tags: #logging, #stdlib