summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--logging/middleware.go7
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,
}