Tweak logging
All checks were successful
Go / build (push) Successful in 1m20s

This commit is contained in:
2023-10-28 09:33:18 +13:00
parent a45deac7c8
commit d703edb282

View File

@@ -51,6 +51,10 @@ func WithLogging(h http.Handler) http.Handler {
remoteAddr = ips[0]
}
}
remoteAddr, _, err := net.SplitHostPort(remoteAddr)
if err != nil {
slog.Error("Failed to format remoteAddr", slog.Any("err", err))
}
responseData := &responseData{
status: 0,
@@ -64,7 +68,7 @@ func WithLogging(h http.Handler) http.Handler {
duration := time.Since(start)
// t=2023-10-27T18:08:47.231895532+13:00 remote_addr=100.114.208.117 time_ms=4 duration=4.914291ms
// t=2023-10-27T18:08:47.231895532+13:00
slog.Info("Request Completed:",
slog.String("method", r.Method),
slog.String("path", r.RequestURI),
@@ -73,7 +77,7 @@ func WithLogging(h http.Handler) http.Handler {
slog.String("referer", r.Referer()),
slog.String("remote_addr", remoteAddr),
slog.Int("status", responseData.status),
slog.Int64("duration", duration.Microseconds()),
slog.String("duration", duration.String()),
slog.Int("size", responseData.size),
)