from messenger.messaging.domain.events import ChatCreated, MessagePosted from messenger.shared.application.ports import Logger LOG_FIELDS = frozenset({"chat_id", "message_id", "count"}) class MessagingJournal: __slots__ = ("_logger",) def __init__(self, logger: Logger) -> None: self._logger = logger async def on_chat_created(self, event: ChatCreated) -> None: self._logger.info( "audit.chat_created", chat_id=str(event.chat_id), actor_id=str(event.creator_id), count=event.member_count, ) async def on_message_posted(self, event: MessagePosted) -> None: self._logger.info( "audit.message_posted", chat_id=str(event.chat_id), actor_id=str(event.sender_id), message_id=str(event.message_id), )