From be7a9e7f0003c9dfedc451bb955fccba6f84bf91 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Thu, 29 Jan 2026 21:17:50 +0000 Subject: [PATCH] Smarter access log formatting with IPv6. --- paskia/fastapi/logging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paskia/fastapi/logging.py b/paskia/fastapi/logging.py index 299dd56..c020623 100644 --- a/paskia/fastapi/logging.py +++ b/paskia/fastapi/logging.py @@ -51,8 +51,8 @@ def format_ipv6_network(ip: str) -> str: network_int >>= 16 # Compress consecutive zero groups result = ":".join(groups) + "::" - # Simplify leading zeros in groups and compress - return str(IPv6Address(result + "0")) + # Simplify leading zeros in groups and compress, then strip trailing :: + return str(IPv6Address(result + "0")).removesuffix("::") except Exception: return ip @@ -93,7 +93,7 @@ def format_access_log( use_color = sys.stderr.isatty() # Format components with fixed widths for alignment - ip = format_client_ip(client).ljust(15) # IPv4 max 15 chars + ip = format_client_ip(client).ljust(19) # IPv6 network max 19 chars timing = f"{duration_ms:.0f}ms" method_padded = method.ljust(7) # Longest method is OPTIONS (7)