MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Formatter

Class Formatter

tools/python-3.11.9-amd64/Lib/logging/__init__.py:531–704  ·  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

Source from the content-addressed store, hash-verified

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

Callers 2

__init__.pyFile · 0.70
basicConfigFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected