mirror of
https://github.com/labstack/echo.git
synced 2025-01-12 01:22:21 +02:00
Add start time to request logger middleware values (#1991)
This commit is contained in:
parent
4651c7aafe
commit
a2e6ca7ed6
@ -124,6 +124,8 @@ type RequestLoggerConfig struct {
|
||||
|
||||
// RequestLoggerValues contains extracted values from logger.
|
||||
type RequestLoggerValues struct {
|
||||
// StartTime is time recorded before next middleware/handler is executed.
|
||||
StartTime time.Time
|
||||
// Latency is duration it took to execute rest of the handler chain (next(c) call).
|
||||
Latency time.Duration
|
||||
// Protocol is request protocol (i.e. `HTTP/1.1` or `HTTP/2`)
|
||||
@ -215,7 +217,9 @@ func (config RequestLoggerConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
|
||||
}
|
||||
err := next(c)
|
||||
|
||||
v := RequestLoggerValues{}
|
||||
v := RequestLoggerValues{
|
||||
StartTime: start,
|
||||
}
|
||||
if config.LogLatency {
|
||||
v.Latency = now().Sub(start)
|
||||
}
|
||||
|
@ -296,6 +296,7 @@ func TestRequestLogger_allFields(t *testing.T) {
|
||||
err := mw(c)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, time.Unix(1631045377, 0), expect.StartTime)
|
||||
assert.Equal(t, 10*time.Second, expect.Latency)
|
||||
assert.Equal(t, "HTTP/1.1", expect.Protocol)
|
||||
assert.Equal(t, "8.8.8.8", expect.RemoteIP)
|
||||
|
Loading…
Reference in New Issue
Block a user