def format(self, entry):
message = entry.message
timestamp = entry.timestamp.to("local")
source = entry.message_dict.get("source")
facility = entry.message_dict.get("facility")
custom_fields = list(self.fields)
log_level = LogLevel.find_by_syslog_code(entry.level)
args = {
'timestamp': timestamp.format(utils.DEFAULT_DATE_FORMAT),
'level': log_level['name'],
'message': self.encode_message(message),
'source': source or '',
'facility': facility or ''
}
for field in custom_fields:
if field not in self.DEFAULT_FIELDS:
args[field] = entry.message_dict.get(field, '')
log = six.u(self.format_template).format(**args)
if self.color:
return colored(log, log_level['color'], log_level['bg_color'])
else:
return log
评论列表
文章目录