From 2cef5ab504d4fab1fccc0623f26bf9a7a3f44dfb Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 8 Mar 2023 09:42:11 -0900 Subject: [PATCH] log request start and stop --- backend/internal/web/mid/logger.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/internal/web/mid/logger.go b/backend/internal/web/mid/logger.go index fb39c67..9c577fa 100644 --- a/backend/internal/web/mid/logger.go +++ b/backend/internal/web/mid/logger.go @@ -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))),