INNER CODE UNIT · Python
to_int
lebinh/ngxtop · ngxtop/ngxtop.py:293
def to_int(value):
return int(value) if value and value != '-' else 0
def to_float(value):
return float(value) if value and value != '-' else 0.0
def parse_caddy_log(lines):
"""Parse Caddy JSON log format and convert to ngxtop's expected format."""
for line in lines:
try:
# Extract the JSON part of the line
# Caddy logs have format: timestamp INFO http.log.access.log2 handled request {json}
# Find "handled request" first, then find the JSON after it
handled_pos = line.find('handled request')
if handled_pos == -1:
# Try to parse as pure JSON if no "handled request" prefix