diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-01 10:25:22 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-01 10:25:22 -0600 |
commit | fdc6d5e60137393c4c507c35556647f3dafc917a (patch) | |
tree | 250586c54138b357fc170b73b371a5f2d97e3a80 /logging/middleware.go | |
parent | a5d8aeb0bb53420a6dc87dcdc72494fa3f44224f (diff) |
include the time spent in the handler for the 'dur' log keyv1.0.0
Diffstat (limited to 'logging/middleware.go')
-rw-r--r-- | logging/middleware.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/logging/middleware.go b/logging/middleware.go index 3b68c15..ffce1b7 100644 --- a/logging/middleware.go +++ b/logging/middleware.go @@ -12,9 +12,10 @@ import ( func LogRequests(logger Logger) sr.Middleware { return func(inner sr.Handler) sr.Handler { return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { + start := time.Now() response := inner.Handle(ctx, request) if response != nil { - response.Body = loggingBody(logger, request, response) + response.Body = loggingBody(logger, request, response, start) } return response @@ -81,12 +82,12 @@ func (lwtr loggedWriteToResponseBody) WriteTo(dst io.Writer) (int64, error) { return n, err } -func loggingBody(logger Logger, request *sr.Request, response *sr.Response) io.Reader { +func loggingBody(logger Logger, request *sr.Request, response *sr.Response, start time.Time) io.Reader { body := &loggedResponseBody{ request: request, response: response, body: response.Body, - start: time.Now(), + start: start, written: 0, logger: logger, } |