diff options
author | Francis Lavoie <[email protected]> | 2021-11-29 01:18:35 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2021-11-29 01:18:35 -0500 |
commit | f55b123d63132e290789bcd07077375c76b6e1dd (patch) | |
tree | 494cf4f8d85f48d5d3bc3a6e12d74d491710d6cd /admin.go | |
parent | 0eb0b60f47bddcf24f6af9265e60044033555ff2 (diff) | |
download | caddy-f55b123d63132e290789bcd07077375c76b6e1dd.tar.gz caddy-f55b123d63132e290789bcd07077375c76b6e1dd.zip |
caddyhttp: Split up logged remote address into IP and port (#4403)
Diffstat (limited to 'admin.go')
-rw-r--r-- | admin.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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 { |