Skip to content

Commit

Permalink
feat: add response_time to middleware logs
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioltonon committed May 5, 2023
1 parent 6f1879e commit 402a08e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion application/http/middleware/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"net/http"
"time"

"convercy/domain/valueobject"
"convercy/shared/logging"
Expand All @@ -13,7 +14,10 @@ import (
func Log(logger logging.Logger) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestID := valueobject.GenerateRequestID()
var (
now = time.Now()
requestID = valueobject.GenerateRequestID()
)

logger.Info("Got request",
logging.String("http_method", r.Method),
Expand All @@ -28,6 +32,7 @@ func Log(logger logging.Logger) mux.MiddlewareFunc {
logger.Info("Returning response",
logging.Stringer("request_id", requestID),
logging.Int("http_status_code", rw.Status()),
logging.Stringer("response_time", time.Since(now)),
)
})
}
Expand Down

0 comments on commit 402a08e

Please sign in to comment.