MCPcopy
hub / github.com/opendevops-cn/opendevops / format

Method format

scripts/tornado_source_code/tornado/log.py:163–207  ·  view source on GitHub ↗
(self, record: Any)

Source from the content-addressed store, hash-verified

161 self._normal = ""
162
163 def format(self, record: Any) -> str:
164 try:
165 message = record.getMessage()
166 assert isinstance(message, basestring_type) # guaranteed by logging
167 # Encoding notes: The logging module prefers to work with character
168 # strings, but only enforces that log messages are instances of
169 # basestring. In python 2, non-ascii bytestrings will make
170 # their way through the logging framework until they blow up with
171 # an unhelpful decoding error (with this formatter it happens
172 # when we attach the prefix, but there are other opportunities for
173 # exceptions further along in the framework).
174 #
175 # If a byte string makes it this far, convert it to unicode to
176 # ensure it will make it out to the logs. Use repr() as a fallback
177 # to ensure that all byte strings can be converted successfully,
178 # but don't do it by default so we don't add extra quotes to ascii
179 # bytestrings. This is a bit of a hacky place to do this, but
180 # it's worth it since the encoding errors that would otherwise
181 # result are so useless (and tornado is fond of using utf8-encoded
182 # byte strings wherever possible).
183 record.message = _safe_unicode(message)
184 except Exception as e:
185 record.message = "Bad message (%r): %r" % (e, record.__dict__)
186
187 record.asctime = self.formatTime(record, cast(str, self.datefmt))
188
189 if record.levelno in self._colors:
190 record.color = self._colors[record.levelno]
191 record.end_color = self._normal
192 else:
193 record.color = record.end_color = ""
194
195 formatted = self._fmt % record.__dict__
196
197 if record.exc_info:
198 if not record.exc_text:
199 record.exc_text = self.formatException(record.exc_info)
200 if record.exc_text:
201 # exc_text contains multiple lines. We need to _safe_unicode
202 # each line separately so that non-utf8 bytes don't cause
203 # all the newlines to turn into '\n'.
204 lines = [formatted.rstrip()]
205 lines.extend(_safe_unicode(ln) for ln in record.exc_text.split("\n"))
206 formatted = "\n".join(lines)
207 return formatted.replace("\n", "\n ")
208
209
210def enable_pretty_logging(options: Any = None, logger: logging.Logger = None) -> None:

Callers 6

getMethod · 0.80
__repr__Method · 0.80
_on_timeoutMethod · 0.80
_on_timeoutMethod · 0.80
url_concatFunction · 0.80
test_already_doneMethod · 0.80

Calls 4

_safe_unicodeFunction · 0.85
splitMethod · 0.80
joinMethod · 0.80
replaceMethod · 0.80

Tested by 1

test_already_doneMethod · 0.64