72 def __init__(self, *, verbose=False, colors_enabled=True):
77 def colorize_line(self, line):
78 if not line.startswith(
'tskv\t'):
82 def colorize_tskv(self, line):
83 row = tskv.parse_line(line)
86 def colorize_row(self, row):
88 flowid =
'-'.join([row.get(key,
'')
for key
in (
'link',
'trace_id')])
90 entry_type = row.pop(
'_type',
None)
91 link = row.get(
'link',
None)
92 level = row.pop(
'level',
'none')
93 text = row.pop(
'text',
'')
96 if entry_type ==
'request':
102 try_reformat_json(row.pop(
'body')), Colors.YELLOW,
105 elif entry_type ==
'response':
106 if 'meta_code' in row:
107 status_code = row.pop(
'meta_code')
112 text =
'Response finished'
116 try_reformat_json(row.pop(
'body')), Colors.YELLOW,
119 elif entry_type ==
'mockserver_request':
120 text =
'Mockserver request finished'
121 if 'meta_code' in row:
122 status_code = str(row.pop(
'meta_code'))
126 for key
in (
'method',
'url',
'status',
'exc_info',
'delay'):
127 value = row.pop(key,
None)
129 extra_fields.append(f
'{key}={value}')
132 logid = f
'[{self._requests[link]}]'
133 elif link
is not None:
138 level_color = LEVEL_COLORS.get(level)
139 flow_color = Colors.colorize(flowid)
142 self.
textcolor(f
'{level:<8}', level_color),
148 fields.append(
'<NO TEXT>')
152 fields.extend(extra_fields)
154 fields.extend([f
'{k}={v}' for k, v
in row.items()])
155 return ' '.join(fields)
157 def textcolor(self, text, color):
160 return f
'{color}{text}{Colors.DEFAULT}'
162 def _http_status(self, key, status):
163 color = HTTP_STATUS_COLORS.get(status[:1], Colors.DEFAULT)
164 return self.
textcolor(f
'{key}={status}', color)
166 def _build_request_info(self, row):
170 method = row.get(
'method',
'UNKNOWN')
171 return f
'{method} {uri}'