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) --- modules/caddyhttp/marshalers.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modules/caddyhttp/marshalers.go') diff --git a/modules/caddyhttp/marshalers.go b/modules/caddyhttp/marshalers.go index bbb703c..c99c94e 100644 --- a/modules/caddyhttp/marshalers.go +++ b/modules/caddyhttp/marshalers.go @@ -16,6 +16,7 @@ package caddyhttp import ( "crypto/tls" + "net" "net/http" "strings" @@ -27,7 +28,14 @@ type LoggableHTTPRequest struct{ *http.Request } // MarshalLogObject satisfies the zapcore.ObjectMarshaler interface. func (r LoggableHTTPRequest) MarshalLogObject(enc zapcore.ObjectEncoder) error { - enc.AddString("remote_addr", r.RemoteAddr) + ip, port, err := net.SplitHostPort(r.RemoteAddr) + if err != nil { + ip = r.RemoteAddr + port = "" + } + + enc.AddString("remote_ip", ip) + enc.AddString("remote_port", port) enc.AddString("proto", r.Proto) enc.AddString("method", r.Method) enc.AddString("host", r.Host) -- cgit v1.2.3