From 590dfe54ee6d8aa33a7720a68c809d2d925ace2a Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Wed, 3 Jan 2024 17:45:22 +0000 Subject: [PATCH] Use request logger properly --- internal/api/routes.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/api/routes.go b/internal/api/routes.go index 5d9af06..0a8ce4b 100644 --- a/internal/api/routes.go +++ b/internal/api/routes.go @@ -6,6 +6,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/gorilla/websocket" + "github.com/rs/zerolog/hlog" "github.com/beeper/registration-relay/internal/provider" ) @@ -19,7 +20,7 @@ func (a *api) bridgeExecuteCommand(w http.ResponseWriter, r *http.Request) { return } - log := a.log.With().Str("code", code).Logger() + log := hlog.FromRequest(r).With().Str("code", code).Logger() provider, exists := provider.GetProvider(code) if !exists { @@ -42,9 +43,11 @@ func (a *api) bridgeExecuteCommand(w http.ResponseWriter, r *http.Request) { } func (a *api) providerWebsocket(w http.ResponseWriter, r *http.Request) { + log := hlog.FromRequest(r) + conn, err := upgrader.Upgrade(w, r, nil) if err != nil { - a.log.Err(err).Msg("Failed to upgrade websocket connection") + log.Err(err).Msg("Failed to upgrade websocket connection") w.WriteHeader(http.StatusInternalServerError) return } @@ -53,5 +56,5 @@ func (a *api) providerWebsocket(w http.ResponseWriter, r *http.Request) { provider := provider.NewProvider(conn, a.secret) provider.WebsocketLoop() - a.log.Info().Msg("Websocket connection closed") + log.Info().Msg("Websocket connection closed") }