summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-11-29 01:18:35 -0500
committerGitHub <noreply@github.com>2021-11-29 01:18:35 -0500
commitf55b123d63132e290789bcd07077375c76b6e1dd (patch)
tree494cf4f8d85f48d5d3bc3a6e12d74d491710d6cd /modules
parent0eb0b60f47bddcf24f6af9265e60044033555ff2 (diff)
caddyhttp: Split up logged remote address into IP and port (#4403)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/marshalers.go10
1 files changed, 9 insertions, 1 deletions
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)