log request start and stop

This commit is contained in:
Hayden 2023-03-08 09:42:11 -09:00
parent 40251a3b49
commit 2cef5ab504
No known key found for this signature in database
GPG key ID: 17CF79474E257545

View file

@ -78,12 +78,22 @@ func SugarLogger(log zerolog.Logger) server.Middleware {
return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
record := &statusRecorder{ResponseWriter: w, Status: http.StatusOK}
err := next.ServeHTTP(record, r) // Blocks until the next handler returns.
url := fmt.Sprintf("%s %s", r.RequestURI, r.Proto)
log.Info().
Str("trace_id", server.GetTraceID(r.Context())).
Str("status", "started").
Msgf("%s %s %s",
bold(fmtCode(record.Status)),
bold(orange(atLeast6(r.Method))),
aqua(url),
)
err := next.ServeHTTP(record, r) // Blocks until the next handler returns.
log.Info().
Str("trace_id", server.GetTraceID(r.Context())).
Str("status", "completed").
Msgf("%s %s %s",
bold(fmtCode(record.Status)),
bold(orange(atLeast6(r.Method))),