MCPcopy
hub / github.com/celery/celery / format

Method format

celery/utils/log.py:145–175  ·  view source on GitHub ↗
(self, record)

Source from the content-addressed store, hash-verified

143 return r
144
145 def format(self, record):
146 msg = super().format(record)
147 color = self.colors.get(record.levelname)
148
149 # reset exception info later for other handlers...
150 einfo = sys.exc_info() if record.exc_info == 1 else record.exc_info
151
152 if color and self.use_color:
153 try:
154 # safe_str will repr the color object
155 # and color will break on non-string objects
156 # so need to reorder calls based on type.
157 # Issue #427
158 try:
159 if isinstance(msg, str):
160 return str(color(safe_str(msg)))
161 return safe_str(color(msg))
162 except UnicodeDecodeError: # pragma: no cover
163 return safe_str(msg) # skip colors
164 except Exception as exc: # pylint: disable=broad-except
165 prev_msg, record.exc_info, record.msg = (
166 record.msg, 1, '<Unrepresentable {!r}: {!r}>'.format(
167 type(msg), exc
168 ),
169 )
170 try:
171 return super().format(record)
172 finally:
173 record.msg, record.exc_info = prev_msg, einfo
174 else:
175 return safe_str(msg)
176
177
178class LoggingProxy:

Callers 15

test_format_objectMethod · 0.95
test_format_raisesMethod · 0.95
warnFunction · 0.45
prettyFunction · 0.45
resolveFunction · 0.45
_format_charsFunction · 0.45
on_crashMethod · 0.45
__repr__Method · 0.45
hfloatFunction · 0.45
worker_directFunction · 0.45
__repr__Method · 0.45
__getitem__Method · 0.45

Calls 1

getMethod · 0.45

Tested by 2

test_format_objectMethod · 0.76
test_format_raisesMethod · 0.76