From 7c227e175de9354614d2bccccf031985100cd9d4 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 30 Oct 2024 10:15:37 -0600 Subject: [PATCH] pre-commit: update and ban Msgf on zerolog logs Signed-off-by: Sumner Evans --- .pre-commit-config.yaml | 3 ++- bridge/commands/event.go | 8 ++++---- bridgev2/commands/event.go | 8 ++++---- crypto/keysharing.go | 10 +++++++--- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8827c231..81701203 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,8 @@ repos: #- id: go-staticcheck-repo-mod - repo: https://github.com/beeper/pre-commit-go - rev: v0.4.1 + rev: v0.4.2 hooks: - id: prevent-literal-http-methods - id: zerolog-ban-global-log + - id: zerolog-ban-msgf diff --git a/bridge/commands/event.go b/bridge/commands/event.go index 42b49b68..49a8b277 100644 --- a/bridge/commands/event.go +++ b/bridge/commands/event.go @@ -66,7 +66,7 @@ func (ce *Event) ReplyAdvanced(msg string, allowMarkdown, allowHTML bool) { content.MsgType = event.MsgNotice _, err := ce.MainIntent().SendMessageEvent(ce.Ctx, ce.RoomID, event.EventMessage, content) if err != nil { - ce.ZLog.Error().Err(err).Msgf("Failed to reply to command") + ce.ZLog.Error().Err(err).Msg("Failed to reply to command") } } @@ -74,7 +74,7 @@ func (ce *Event) ReplyAdvanced(msg string, allowMarkdown, allowHTML bool) { func (ce *Event) React(key string) { _, err := ce.MainIntent().SendReaction(ce.Ctx, ce.RoomID, ce.EventID, key) if err != nil { - ce.ZLog.Error().Err(err).Msgf("Failed to react to command") + ce.ZLog.Error().Err(err).Msg("Failed to react to command") } } @@ -82,7 +82,7 @@ func (ce *Event) React(key string) { func (ce *Event) Redact(req ...mautrix.ReqRedact) { _, err := ce.MainIntent().RedactEvent(ce.Ctx, ce.RoomID, ce.EventID, req...) if err != nil { - ce.ZLog.Error().Err(err).Msgf("Failed to redact command") + ce.ZLog.Error().Err(err).Msg("Failed to redact command") } } @@ -90,6 +90,6 @@ func (ce *Event) Redact(req ...mautrix.ReqRedact) { func (ce *Event) MarkRead() { err := ce.MainIntent().SendReceipt(ce.Ctx, ce.RoomID, ce.EventID, event.ReceiptTypeRead, nil) if err != nil { - ce.ZLog.Error().Err(err).Msgf("Failed to mark command as read") + ce.ZLog.Error().Err(err).Msg("Failed to mark command as read") } } diff --git a/bridgev2/commands/event.go b/bridgev2/commands/event.go index bd2c52d2..78ed94bb 100644 --- a/bridgev2/commands/event.go +++ b/bridgev2/commands/event.go @@ -58,7 +58,7 @@ func (ce *Event) ReplyAdvanced(msg string, allowMarkdown, allowHTML bool) { content.MsgType = event.MsgNotice _, err := ce.Bot.SendMessage(ce.Ctx, ce.OrigRoomID, event.EventMessage, &event.Content{Parsed: &content}, nil) if err != nil { - ce.Log.Err(err).Msgf("Failed to reply to command") + ce.Log.Err(err).Msg("Failed to reply to command") } } @@ -74,7 +74,7 @@ func (ce *Event) React(key string) { }, }, nil) if err != nil { - ce.Log.Err(err).Msgf("Failed to react to command") + ce.Log.Err(err).Msg("Failed to react to command") } } @@ -86,7 +86,7 @@ func (ce *Event) Redact(req ...mautrix.ReqRedact) { }, }, nil) if err != nil { - ce.Log.Err(err).Msgf("Failed to redact command") + ce.Log.Err(err).Msg("Failed to redact command") } } @@ -95,6 +95,6 @@ func (ce *Event) MarkRead() { // TODO //err := ce.Bot.SendReceipt(ce.Ctx, ce.RoomID, ce.EventID, event.ReceiptTypeRead, nil) //if err != nil { - // ce.Log.Err(err).Msgf("Failed to mark command as read") + // ce.Log.Err(err).Msg("Failed to mark command as read") //} } diff --git a/crypto/keysharing.go b/crypto/keysharing.go index 38e015c6..0ccf006a 100644 --- a/crypto/keysharing.go +++ b/crypto/keysharing.go @@ -59,11 +59,15 @@ func (mach *OlmMachine) RequestRoomKey(ctx context.Context, toUser id.UserID, to select { case <-keyResponseReceived: // key request successful - mach.Log.Debug().Msgf("Key for session %v was received, cancelling other key requests", sessionID) + mach.Log.Debug(). + Stringer("session_id", sessionID). + Msg("Key for session was received, cancelling other key requests") resChan <- true case <-ctx.Done(): // if the context is done, key request was unsuccessful - mach.Log.Debug().Msgf("Context closed (%v) before forwared key for session %v received, sending key request cancellation", ctx.Err(), sessionID) + mach.Log.Debug().Err(err). + Stringer("session_id", sessionID). + Msg("Context closed before forwarded key for session received, sending key request cancellation") resChan <- false } @@ -332,7 +336,7 @@ func (mach *OlmMachine) HandleRoomKeyRequest(ctx context.Context, sender id.User } if internalID := igs.ID(); internalID != content.Body.SessionID { // Should this be an error? - log = log.With().Str("unexpected_session_id", internalID.String()).Logger() + log = log.With().Stringer("unexpected_session_id", internalID).Logger() } firstKnownIndex := igs.Internal.FirstKnownIndex()