MCPcopy Index your code
hub / github.com/python/cpython / Formatter

Class Formatter

Lib/logging/__init__.py:551–729  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

549}
550
551class Formatter(object):
552 """
553 Formatter instances are used to convert a LogRecord to text.
554
555 Formatters need to know how a LogRecord is constructed. They are
556 responsible for converting a LogRecord to (usually) a string which can
557 be interpreted by either a human or an external system. The base Formatter
558 allows a formatting string to be specified. If none is supplied, the
559 style-dependent default value, "%(message)s", "{message}", or
560 "${message}", is used.
561
562 The Formatter can be initialized with a format string which makes use of
563 knowledge of the LogRecord attributes - e.g. the default value mentioned
564 above makes use of the fact that the user's message and arguments are pre-
565 formatted into a LogRecord's message attribute. Currently, the useful
566 attributes in a LogRecord are described by:
567
568 %(name)s Name of the logger (logging channel)
569 %(levelno)s Numeric logging level for the message (DEBUG, INFO,
570 WARNING, ERROR, CRITICAL)
571 %(levelname)s Text logging level for the message ("DEBUG", "INFO",
572 "WARNING", "ERROR", "CRITICAL")
573 %(pathname)s Full pathname of the source file where the logging
574 call was issued (if available)
575 %(filename)s Filename portion of pathname
576 %(module)s Module (name portion of filename)
577 %(lineno)d Source line number where the logging call was issued
578 (if available)
579 %(funcName)s Function name
580 %(created)f Time when the LogRecord was created (time.time_ns() / 1e9
581 return value)
582 %(asctime)s Textual time when the LogRecord was created
583 %(msecs)d Millisecond portion of the creation time
584 %(relativeCreated)d Time in milliseconds when the LogRecord was created,
585 relative to the time the logging module was loaded
586 (typically at application startup time)
587 %(thread)d Thread ID (if available)
588 %(threadName)s Thread name (if available)
589 %(taskName)s Task name (if available)
590 %(process)d Process ID (if available)
591 %(processName)s Process name (if available)
592 %(message)s The result of record.getMessage(), computed just as
593 the record is emitted
594 """
595
596 converter = time.localtime
597
598 def __init__(self, fmt=None, datefmt=None, style='%', validate=True, *,
599 defaults=None):
600 """
601 Initialize the formatter with specified format strings.
602
603 Initialize the formatter either with the specified format string, or a
604 default as described above. Allow for specialized date formatting with
605 the optional datefmt argument. If datefmt is omitted, you get an
606 ISO8601-like (or RFC 3339-like) format.
607
608 Use a style parameter of '%', '{' or '$' to specify that you want to

Callers 2

__init__.pyFile · 0.70
basicConfigFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…