INNER CODE UNIT · Python
parse_log
lebinh/ngxtop · ngxtop/ngxtop.py:414
def parse_log(lines, pattern):
# Handle Caddy format separately
if pattern == 'caddy':
return parse_caddy_log(lines)
# Regular nginx/apache log parsing
matches = (pattern.match(l) for l in lines)
records = (m.groupdict() for m in matches if m is not None)
records = map_field('status', to_int, records)
records = add_field('status_type', parse_status_type, records)
records = add_field('bytes_sent', lambda r: r['body_bytes_sent'], records)
records = map_field('bytes_sent', to_int, records)
records = map_field('request_time', to_float, records)
records = add_field('request_path', parse_request_path, records)
return records
# =================================