From f55b123d63132e290789bcd07077375c76b6e1dd Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 29 Nov 2021 01:18:35 -0500 Subject: caddyhttp: Split up logged remote address into IP and port (#4403) --- admin.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'admin.go') diff --git a/admin.go b/admin.go index 684526d..6960de5 100644 --- a/admin.go +++ b/admin.go @@ -659,11 +659,17 @@ type adminHandler struct { // ServeHTTP is the external entry point for API requests. // It will only be called once per request. func (h adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + ip, port, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + ip = r.RemoteAddr + port = "" + } log := Log().Named("admin.api").With( zap.String("method", r.Method), zap.String("host", r.Host), zap.String("uri", r.RequestURI), - zap.String("remote_addr", r.RemoteAddr), + zap.String("remote_ip", ip), + zap.String("remote_port", port), zap.Reflect("headers", r.Header), ) if r.TLS != nil { -- cgit v1.2.3