PyDocs

Nav

Generic Operating System Services

Formatter

logging

class (source)
  • Formatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)
Formatter instances are used to convert a LogRecord to text.

Formatters need to know how a LogRecord is constructed. They are
responsible for converting a LogRecord to (usually) a string which can
be interpreted by either a human or an external system. The base Formatter
allows a formatting string to be specified. If none is supplied, the
style-dependent default value, "%(message)s", "{message}", or
"${message}", is used.

The Formatter can be initialized with a format string which makes use of
knowledge of the LogRecord attributes - e.g. the default value mentioned
above makes use of the fact that the user's message and arguments are pre-
formatted into a LogRecord's message attribute. Currently, the useful
attributes in a LogRecord are described by:

%(name)s            Name of the logger (logging channel)
%(levelno)s         Numeric logging level for the message (DEBUG, INFO,
                    WARNING, ERROR, CRITICAL)
%(levelname)s       Text logging level for the message ("DEBUG", "INFO",
                    "WARNING", "ERROR", "CRITICAL")
%(pathname)s        Full pathname of the source file where the logging
                    call was issued (if available)
%(filename)s        Filename portion of pathname
%(module)s          Module (name portion of filename)
%(lineno)d          Source line number where the logging call was issued
                    (if available)
%(funcName)s        Function name
%(created)f         Time when the LogRecord was created (time.time_ns() / 1e9
                    return value)
%(asctime)s         Textual time when the LogRecord was created
%(msecs)d           Millisecond portion of the creation time
%(relativeCreated)d Time in milliseconds when the LogRecord was created,
                    relative to the time the logging module was loaded
                    (typically at application startup time)
%(thread)d          Thread ID (if available)
%(threadName)s      Thread name (if available)
%(taskName)s        Task name (if available)
%(process)d         Process ID (if available)
%(processName)s     Process name (if available)
%(message)s         The result of record.getMessage(), computed just as
                    the record is emitted
Changed in 3.2, 3.8, 3.10
  • 3.2: Added the style parameter.
  • 3.8: Added the validate parameter.
  • 3.10: Added the defaults parameter.
Members of Formatter

f

format
Format the specified record as text.
formatException
Format and return the specified exception information as a string.
formatStack
This method is provided as an extension point for specialized formatting of stack information.
formatTime
Return the creation time of the specified LogRecord as formatted text.
0 Examples
No examples for logging/Formatter.
See Also
No see-alsos for logging/Formatter
0 Notes
No notes for Formatter