MCPcopy
hub / github.com/StackStorm/st2 / format

Method format

st2common/st2common/logging/formatters.py:247–286  ·  view source on GitHub ↗
(self, record)

Source from the content-addressed store, hash-verified

245 DEFAULT_LOG_LEVEL = 6 # info
246
247 def format(self, record):
248 attributes = self._get_extra_attributes(record=record)
249 attributes = self._format_extra_attributes(attributes=attributes)
250
251 msg = record.msg
252 exc_info = record.exc_info
253 time_now_float = record.created
254 time_now_sec = int(time_now_float)
255 level = self.PYTHON_TO_GELF_LEVEL_MAP.get(
256 record.levelno, self.DEFAULT_LOG_LEVEL
257 )
258
259 common_attributes = self._get_common_extra_attributes(record=record)
260 full_msg = super(GelfLogFormatter, self).format(record)
261
262 data = {
263 "version": GELF_SPEC_VERSION,
264 "host": HOSTNAME,
265 "short_message": msg,
266 "full_message": full_msg,
267 "timestamp": time_now_sec,
268 "timestamp_f": time_now_float,
269 "level": level,
270 }
271
272 if exc_info:
273 # Include exception information
274 exc_type, exc_value, exc_tb = exc_info
275 tb_str = "".join(traceback.format_tb(exc_tb))
276 data["_exception"] = six.text_type(exc_value)
277 data["_traceback"] = tb_str
278
279 # Include common Python log record attributes
280 data["_python"] = common_attributes
281
282 # Include user extra attributes
283 data.update(attributes)
284
285 msg = json.dumps(data, cls=ObjectJSONEncoder)
286 return msg

Callers 15

test_formatMethod · 0.95
setup.pyFile · 0.45
test_formatMethod · 0.45
test_format_tz_naiveMethod · 0.45
test_format_tz_awareMethod · 0.45
assertEndsWithMethod · 0.45
setUpMethod · 0.45
test_datetime_rangeMethod · 0.45

Calls 5

_get_extra_attributesMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by 12

test_formatMethod · 0.76
test_formatMethod · 0.36
test_format_tz_naiveMethod · 0.36
test_format_tz_awareMethod · 0.36
assertEndsWithMethod · 0.36
setUpMethod · 0.36
test_datetime_rangeMethod · 0.36