INNER CODE UNIT · Python

to_float

lebinh/ngxtop · ngxtop/ngxtop.py:297

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
                json_start = line.find('{')
            else:
                # Find the first { after "handled request"
                json_start = line.find('{', handled_pos + len('handled request'))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…