From 1349c3f80104e4ade21e5923d9e462f6e26df6b7 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 30 Dec 2023 11:57:15 -0700 Subject: [PATCH] provisioning/StartPM: use structured logging Signed-off-by: Sumner Evans --- provisioning.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/provisioning.go b/provisioning.go index 5658bf44..e3470a97 100644 --- a/provisioning.go +++ b/provisioning.go @@ -235,16 +235,22 @@ func (prov *ProvisioningAPI) ResolveIdentifier(w http.ResponseWriter, r *http.Re func (prov *ProvisioningAPI) StartPM(w http.ResponseWriter, r *http.Request) { user := r.Context().Value("user").(*User) phoneNum, _ := mux.Vars(r)["phonenum"] - prov.log.Debug().Msgf("StartPM from %v, phone number: %v", user.MXID, phoneNum) + + log := prov.log.With(). + Str("action", "start_pm"). + Str("user_id", user.MXID.String()). + Str("phone_num", phoneNum). + Logger() + log.Debug().Msg("starting private message") status, resp, err := prov.resolveIdentifier(user, phoneNum) if err != nil { errCode := "M_INTERNAL" if status == http.StatusNotFound { - prov.log.Debug().Msgf("StartPM from %v, contact not found", user.MXID) + log.Debug().Msg("contact not found") errCode = "M_NOT_FOUND" } else { - prov.log.Err(err).Msgf("StartPM from %v, error looking up contact", user.MXID) + log.Err(err).Msg("error looking up contact") } jsonResponse(w, status, Error{ Success: false, @@ -257,7 +263,7 @@ func (prov *ProvisioningAPI) StartPM(w http.ResponseWriter, r *http.Request) { portal := user.GetPortalByChatID(resp.ChatID.UUID) if portal.MXID == "" { if err := portal.CreateMatrixRoom(user, nil); err != nil { - prov.log.Err(err).Msgf("StartPM from %v, error creating Matrix room", user.MXID) + log.Err(err).Msg("error looking up contact") jsonResponse(w, http.StatusInternalServerError, Error{ Success: false, Error: "Error creating Matrix room",