Include room ID in portal logger

This commit is contained in:
Tulir Asokan 2023-08-02 15:01:50 +03:00
parent b45185beab
commit 20599e93f3
2 changed files with 14 additions and 10 deletions

View file

@ -183,26 +183,30 @@ func (portal *Portal) GetUsers() []*User {
return nil return nil
} }
func (br *GMBridge) newBlankPortal(key database.Key) *Portal { func (portal *Portal) updateLogger() {
portal.zlog = portal.bridge.ZLog.With().
Str("portal_id", portal.ID).
Int("portal_receiver", portal.Receiver).
Str("room_id", portal.MXID.String()).
Logger()
}
func (br *GMBridge) NewPortal(dbPortal *database.Portal) *Portal {
portal := &Portal{ portal := &Portal{
Portal: dbPortal,
bridge: br, bridge: br,
zlog: br.ZLog.With().Str("portal_id", key.ID).Int("portal_receiver", key.Receiver).Logger(),
messages: make(chan PortalMessage, br.Config.Bridge.PortalMessageBuffer), messages: make(chan PortalMessage, br.Config.Bridge.PortalMessageBuffer),
matrixMessages: make(chan PortalMatrixMessage, br.Config.Bridge.PortalMessageBuffer), matrixMessages: make(chan PortalMatrixMessage, br.Config.Bridge.PortalMessageBuffer),
outgoingMessages: make(map[string]*outgoingMessage), outgoingMessages: make(map[string]*outgoingMessage),
} }
portal.updateLogger()
go portal.handleMessageLoop() go portal.handleMessageLoop()
return portal return portal
} }
func (br *GMBridge) NewPortal(dbPortal *database.Portal) *Portal {
portal := br.newBlankPortal(dbPortal.Key)
portal.Portal = dbPortal
return portal
}
const recentlyHandledLength = 100 const recentlyHandledLength = 100
type PortalMessage struct { type PortalMessage struct {
@ -1067,11 +1071,12 @@ func (portal *Portal) CreateMatrixRoom(user *User, conv *gmproto.Conversation) e
if err != nil { if err != nil {
return err return err
} }
portal.zlog.Info().Str("room_id", resp.RoomID.String()).Msg("Matrix room created") portal.zlog.Info().Str("new_room_id", resp.RoomID.String()).Msg("Matrix room created")
portal.InSpace = false portal.InSpace = false
portal.NameSet = len(req.Name) > 0 portal.NameSet = len(req.Name) > 0
portal.forwardBackfillLock.Lock() portal.forwardBackfillLock.Lock()
portal.MXID = resp.RoomID portal.MXID = resp.RoomID
portal.updateLogger()
portal.bridge.portalsLock.Lock() portal.bridge.portalsLock.Lock()
portal.bridge.portalsByMXID[portal.MXID] = portal portal.bridge.portalsByMXID[portal.MXID] = portal
portal.bridge.portalsLock.Unlock() portal.bridge.portalsLock.Unlock()

View file

@ -802,7 +802,6 @@ func (user *User) syncConversation(v *gmproto.Conversation, source string) {
Str("action", "sync conversation"). Str("action", "sync conversation").
Str("conversation_status", updateType.String()). Str("conversation_status", updateType.String()).
Str("data_source", source). Str("data_source", source).
Str("room_id", portal.MXID.String()).
Interface("conversation_data", convCopy). Interface("conversation_data", convCopy).
Logger() Logger()
if portal.MXID != "" { if portal.MXID != "" {