MCPcopy Create free account
hub / github.com/EasyIME/PIME / LogFormatter

Class LogFormatter

python/python3/tornado/log.py:81–212  ·  view source on GitHub ↗

Log formatter used in Tornado. Key features of this formatter are: * Color support when logging to a terminal that supports it. * Timestamps on every log line. * Robust against str/bytes encoding problems. This formatter is enabled automatically by `tornado.options.parse_c

Source from the content-addressed store, hash-verified

79
80
81class LogFormatter(logging.Formatter):
82 """Log formatter used in Tornado.
83
84 Key features of this formatter are:
85
86 * Color support when logging to a terminal that supports it.
87 * Timestamps on every log line.
88 * Robust against str/bytes encoding problems.
89
90 This formatter is enabled automatically by
91 `tornado.options.parse_command_line` or `tornado.options.parse_config_file`
92 (unless ``--logging=none`` is used).
93
94 Color support on Windows versions that do not support ANSI color codes is
95 enabled by use of the colorama__ library. Applications that wish to use
96 this must first initialize colorama with a call to ``colorama.init``.
97 See the colorama documentation for details.
98
99 __ https://pypi.python.org/pypi/colorama
100
101 .. versionchanged:: 4.5
102 Added support for ``colorama``. Changed the constructor
103 signature to be compatible with `logging.config.dictConfig`.
104 """
105
106 DEFAULT_FORMAT = "%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s" # noqa: E501
107 DEFAULT_DATE_FORMAT = "%y%m%d %H:%M:%S"
108 DEFAULT_COLORS = {
109 logging.DEBUG: 4, # Blue
110 logging.INFO: 2, # Green
111 logging.WARNING: 3, # Yellow
112 logging.ERROR: 1, # Red
113 logging.CRITICAL: 5, # Magenta
114 }
115
116 def __init__(
117 self,
118 fmt: str = DEFAULT_FORMAT,
119 datefmt: str = DEFAULT_DATE_FORMAT,
120 style: str = "%",
121 color: bool = True,
122 colors: Dict[int, int] = DEFAULT_COLORS,
123 ) -> None:
124 r"""
125 :arg bool color: Enables color support.
126 :arg str fmt: Log message format.
127 It will be applied to the attributes dict of log records. The
128 text between ``%(color)s`` and ``%(end_color)s`` will be colored
129 depending on the level if color support is on.
130 :arg dict colors: color mappings from logging level to terminal color
131 code
132 :arg str datefmt: Datetime format.
133 Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.
134
135 .. versionchanged:: 3.2
136
137 Added ``fmt`` and ``datefmt`` arguments.
138 """

Callers 2

setUpMethod · 0.90
enable_pretty_loggingFunction · 0.85

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72