Skip to content

Commit a2e6ca7

Browse files
authored
Add start time to request logger middleware values (#1991)
1 parent 4651c7a commit a2e6ca7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

middleware/request_logger.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ type RequestLoggerConfig struct {
124124

125125
// RequestLoggerValues contains extracted values from logger.
126126
type RequestLoggerValues struct {
127+
// StartTime is time recorded before next middleware/handler is executed.
128+
StartTime time.Time
127129
// Latency is duration it took to execute rest of the handler chain (next(c) call).
128130
Latency time.Duration
129131
// Protocol is request protocol (i.e. `HTTP/1.1` or `HTTP/2`)
@@ -215,7 +217,9 @@ func (config RequestLoggerConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
215217
}
216218
err := next(c)
217219

218-
v := RequestLoggerValues{}
220+
v := RequestLoggerValues{
221+
StartTime: start,
222+
}
219223
if config.LogLatency {
220224
v.Latency = now().Sub(start)
221225
}

middleware/request_logger_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func TestRequestLogger_allFields(t *testing.T) {
296296
err := mw(c)
297297

298298
assert.NoError(t, err)
299+
assert.Equal(t, time.Unix(1631045377, 0), expect.StartTime)
299300
assert.Equal(t, 10*time.Second, expect.Latency)
300301
assert.Equal(t, "HTTP/1.1", expect.Protocol)
301302
assert.Equal(t, "8.8.8.8", expect.RemoteIP)

0 commit comments

Comments
 (0)