Thanks for this package, it's exactly what I needed.
My only problem is that the app is behind a proxy, so r.RemoteAddr is always the IP of the proxy, which is of limited use. It would be very helpful to be able to alter this value, for example so it's read from a configurable header.
I think this could be implemented in two ways:
- Add an option for the sloghttp object that is a callback that allows returning the IP of the client, so the app developer will choose how to compute that
- Allow specifying the IP ranges of "trusted proxies" (e.g.
TrustedProxies: []string{"10.0.0.0/8"}). When RemoteAddr is the one of a trusted proxy, read the value of X-Forwarded-For. It should be possible to make the header's name configurable too (e.g. use X-Real-IP or something else)
While we're at it, I think it would be helpful to add an option to omit the IP entirely in the log, since IPs are normally considered PII and can create compliance issues with privacy regulations.
Thanks for this package, it's exactly what I needed.
My only problem is that the app is behind a proxy, so
r.RemoteAddris always the IP of the proxy, which is of limited use. It would be very helpful to be able to alter this value, for example so it's read from a configurable header.I think this could be implemented in two ways:
TrustedProxies: []string{"10.0.0.0/8"}). WhenRemoteAddris the one of a trusted proxy, read the value ofX-Forwarded-For. It should be possible to make the header's name configurable too (e.g. useX-Real-IPor something else)While we're at it, I think it would be helpful to add an option to omit the IP entirely in the log, since IPs are normally considered PII and can create compliance issues with privacy regulations.