From 4b5dceaf1cca184a47fae64d41497c4a3e98f5b5 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sat, 30 Dec 2023 15:29:31 -0700 Subject: [PATCH] fixup! user: use structured logging Signed-off-by: Sumner Evans --- user.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/user.go b/user.go index 00f50c58..8e585275 100644 --- a/user.go +++ b/user.go @@ -338,7 +338,9 @@ func (user *User) startupTryConnect(retryCount int) { for { var connectionStatus signalmeow.SignalConnectionStatus if peekedConnectionStatus.Event != signalmeow.SignalConnectionEventNone { - user.log.Debug().Msgf("Using peeked connectionStatus event: %v", peekedConnectionStatus.Event) + user.log.Debug(). + Str("peeked_connection_status_event", peekedConnectionStatus.Event.String()). + Msg("Using peeked connectionStatus event") connectionStatus = peekedConnectionStatus peekedConnectionStatus = signalmeow.SignalConnectionStatus{} } else { @@ -513,26 +515,30 @@ func (user *User) populateSignalDevice() *signalmeow.Device { } func updatePuppetWithSignalContact(ctx context.Context, user *User, puppet *Puppet, newContactAvatar *signalmeow.ContactAvatar) error { + log := user.log.With(). + Str("action", "update_puppet_with_signal_contact"). + Str("signal_id", puppet.SignalID). + Logger() contact, newProfileAvatar, err := user.SignalDevice.ContactByIDWithProfileAvatar(puppet.SignalID) if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error retrieving contact") + log.Err(err).Msg("error retrieving contact") return err } name := user.bridge.Config.Bridge.FormatDisplayname(contact) if name != puppet.Name { - user.log.Debug().Msgf("updatePuppetWithSignalContact: updating puppet name to %s", name) + log.Debug().Str("new_name", name).Msg("updating puppet name") puppet.Name = name puppet.NameSet = false err = puppet.DefaultIntent().SetDisplayName(name) if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error setting display name") + log.Err(err).Msg("error setting display name") return err } puppet.NameSet = true err = puppet.Update() if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error updating puppet with new name") + log.Err(err).Msg("error updating puppet with new name") return err } } @@ -549,18 +555,18 @@ func updatePuppetWithSignalContact(ctx context.Context, user *User, puppet *Pupp } if preferredAvatarHash == "" && puppet.AvatarSet { - user.log.Debug().Msg("updatePuppetWithSignalContact: clearing avatar") + log.Debug().Msg("clearing avatar") puppet.AvatarSet = false puppet.AvatarURL = id.ContentURI{} puppet.AvatarHash = "" err = puppet.DefaultIntent().SetAvatarURL(id.ContentURI{}) if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error clearing avatar url") + log.Err(err).Msg("error clearing avatar url") return err } err = puppet.Update() if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error updating puppet while clearing avatar") + log.Err(err).Msg("error updating puppet while clearing avatar") return err } return nil @@ -568,10 +574,10 @@ func updatePuppetWithSignalContact(ctx context.Context, user *User, puppet *Pupp // If avatar is set, we must have a new avatar image, so update it if newAvatar != nil { - user.log.Debug().Msg("updatePuppetWithSignalContact: uploading avatar") + log.Debug().Msg("uploading avatar") avatarURL, err := puppet.DefaultIntent().UploadBytes(newAvatar.Image, newAvatar.ContentType) if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error uploading avatar") + log.Err(err).Msg("error uploading avatar") return err } puppet.AvatarURL = avatarURL.ContentURI @@ -580,12 +586,12 @@ func updatePuppetWithSignalContact(ctx context.Context, user *User, puppet *Pupp err = puppet.DefaultIntent().SetAvatarURL(avatarURL.ContentURI) if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error setting avatar url") + log.Err(err).Msg("error setting avatar URL") return err } err = puppet.Update() if err != nil { - user.log.Err(err).Msg("updatePuppetWithSignalContact: error updating puppet with new avatar") + log.Err(err).Msg("error updating puppet with new avatar") return err } }