Smarter access log formatting with IPv6.
This commit is contained in:
@@ -51,8 +51,8 @@ def format_ipv6_network(ip: str) -> str:
|
|||||||
network_int >>= 16
|
network_int >>= 16
|
||||||
# Compress consecutive zero groups
|
# Compress consecutive zero groups
|
||||||
result = ":".join(groups) + "::"
|
result = ":".join(groups) + "::"
|
||||||
# Simplify leading zeros in groups and compress
|
# Simplify leading zeros in groups and compress, then strip trailing ::
|
||||||
return str(IPv6Address(result + "0"))
|
return str(IPv6Address(result + "0")).removesuffix("::")
|
||||||
except Exception:
|
except Exception:
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ def format_access_log(
|
|||||||
use_color = sys.stderr.isatty()
|
use_color = sys.stderr.isatty()
|
||||||
|
|
||||||
# Format components with fixed widths for alignment
|
# 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"
|
timing = f"{duration_ms:.0f}ms"
|
||||||
method_padded = method.ljust(7) # Longest method is OPTIONS (7)
|
method_padded = method.ljust(7) # Longest method is OPTIONS (7)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user