Skip to content

Commit

Permalink
user: use structured logging
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Dec 30, 2023
1 parent bb7615b commit 7b7ee8e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (br *SignalBridge) NewUser(dbUser *database.User) *User {
user := &User{
User: dbUser,
bridge: br,
log: br.ZLog.With().Str("user_id", string(dbUser.MXID)).Logger(),
log: br.ZLog.With().Str("user_id", dbUser.MXID.String()).Logger(),

PermissionLevel: br.Config.Bridge.Permissions.Get(dbUser.MXID),
}
Expand All @@ -194,6 +194,7 @@ func (br *SignalBridge) NewUser(dbUser *database.User) *User {
}

func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID, isDirect bool) (ok bool) {
log := user.log.With().Str("action", "ensure_invited").Str("room_id", roomID.String()).Logger()
if user.bridge.StateStore.GetMembership(roomID, user.MXID) == event.MembershipJoin {
ok = true
return
Expand All @@ -204,10 +205,10 @@ func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID,
}
customPuppet := user.bridge.GetPuppetByCustomMXID(user.MXID)
if customPuppet != nil && customPuppet.CustomIntent() != nil {
user.log.Debug().Msgf("adding will_auto_accept for %s", user.MXID)
log.Debug().Msg("adding will_auto_accept to invite content")
extraContent["fi.mau.will_auto_accept"] = true
} else {
user.log.Debug().Msgf("NOT adding will_auto_accept for %s", user.MXID)
log.Debug().Msg("NOT adding will_auto_accept to invite content")
}
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: user.MXID}, extraContent)
var httpErr mautrix.HTTPError
Expand All @@ -216,16 +217,16 @@ func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID,
ok = true
return
} else if err != nil {
user.log.Warn().Err(err).Msgf("Failed to invite user to %s", roomID)
log.Warn().Err(err).Msg("Failed to invite user to room")
} else {
ok = true
}

if customPuppet != nil && customPuppet.CustomIntent() != nil {
user.log.Debug().Msgf("ensuring joined for %s", user.MXID)
log.Debug().Msg("ensuring custom puppet is joined")
err = customPuppet.CustomIntent().EnsureJoined(roomID, appservice.EnsureJoinedParams{IgnoreCache: true})
if err != nil {
user.log.Warn().Err(err).Msgf("Failed to auto-join %s", roomID)
log.Warn().Err(err).Msg("Failed to auto-join custom puppet")
ok = false
} else {
ok = true
Expand Down Expand Up @@ -487,18 +488,22 @@ func (user *User) Connect() {
func (user *User) populateSignalDevice() *signalmeow.Device {
user.Lock()
defer user.Unlock()
log := user.log.With().
Str("action", "populate_signal_device").
Str("signal_id", user.SignalID).
Logger()

if user.SignalID == "" {
return nil
}

device, err := user.bridge.MeowStore.DeviceByAci(user.SignalID)
if err != nil {
user.log.Err(err).Msgf("problem looking up aci %s", user.SignalID)
log.Err(err).Msg("problem looking up ACI")
return nil
}
if device == nil {
user.log.Err(ErrNotLoggedIn).Msgf("no device found for aci %s", user.SignalID)
log.Err(ErrNotLoggedIn).Msg("no device found for ACI")
return nil
}

Expand Down

0 comments on commit 7b7ee8e

Please sign in to comment.