Skip to content

Commit 432761e

Browse files
committed
#3663: add latency to HTTP access logging
1 parent c98a4f6 commit 432761e

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

http/requestlogger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func requestLoggerMiddleware(skipper middleware.Skipper, logger *logrus.Entry) e
3737
LogMethod: true,
3838
LogRemoteIP: true,
3939
LogError: true,
40+
LogLatency: true,
4041
LogValuesFunc: func(c echo.Context, values middleware.RequestLoggerValues) error {
4142
status := values.Status
4243
if values.Error != nil {
@@ -47,6 +48,7 @@ func requestLoggerMiddleware(skipper middleware.Skipper, logger *logrus.Entry) e
4748
"remote_ip": values.RemoteIP,
4849
"method": values.Method,
4950
"uri": values.URI,
51+
"duration": values.Latency,
5052
"status": status,
5153
}
5254
if logger.Level >= logrus.DebugLevel {

http/requestlogger_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"net/http"
3333
"net/http/httptest"
3434
"testing"
35+
"time"
3536
)
3637

3738
func Test_requestLoggerMiddleware(t *testing.T) {
@@ -57,6 +58,7 @@ func Test_requestLoggerMiddleware(t *testing.T) {
5758
assert.Equal(t, "::1", hook.LastEntry().Data["remote_ip"])
5859
assert.Equal(t, http.StatusNoContent, hook.LastEntry().Data["status"])
5960
assert.Equal(t, "/test", hook.LastEntry().Data["uri"])
61+
assert.NotEmpty(t, hook.LastEntry().Data["duration"].(time.Duration))
6062
})
6163

6264
t.Run("it handles echo.HTTPErrors", func(t *testing.T) {

0 commit comments

Comments
 (0)