Skip to content

Commit

Permalink
Use request logger properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Jan 5, 2024
1 parent 407fb4b commit 590dfe5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand All @@ -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
}
Expand All @@ -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")
}

0 comments on commit 590dfe5

Please sign in to comment.