Formatters have the following attributes and methods. 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 default value of '%(message)s'
is used.
A Formatter can be initialized with a format string which makes use of knowledge of the LogRecord attributes - such as the default value mentioned above making use of the fact that the user's message and arguments are pre-formatted into a LogRecord's message attribute. This format string contains standard python %-style mapping keys. See section 3.6.2, ``String Formatting Operations,'' for more information on string formatting.
Currently, the useful mapping keys in a LogRecord are:
Format | Description |
---|---|
%(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). |
%(funcName)s |
Name of function containing the logging call. |
%(lineno)d |
Source line number where the logging call was issued (if available). |
%(created)f |
Time when the LogRecord was created (as returned by time.time()). |
%(relativeCreated)d |
Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded. |
%(asctime)s |
Human-readable time when the LogRecord was created. By default this is of the form ``2003-07-08 16:49:45,896'' (the numbers after the comma are millisecond portion of the time). |
%(msecs)d |
Millisecond portion of the time when the LogRecord was created. |
%(thread)d |
Thread ID (if available). |
%(threadName)s |
Thread name (if available). |
%(process)d |
Process ID (if available). |
%(message)s |
The logged message, computed as msg % args . |
Changed in version 2.5: funcName was added.
[fmt[, datefmt]]) |
'%(message)s'
is used. If no datefmt
is specified, the ISO8601 date format is used.
record) |
'(asctime)'
, formatTime() is called to format the
event time. If there is exception information, it is formatted using
formatException() and appended to the message.
record[, datefmt]) |
exc_info) |
See About this document... for information on suggesting changes.