kopia lustrzana https://github.com/Yakifo/amqtt
Merge branch 'rc' into optimize_fire_events
commit
73d4937bf3
|
@ -3,6 +3,7 @@ from functools import partial
|
|||
import logging
|
||||
from typing import Any, TypeAlias
|
||||
|
||||
from amqtt.events import BrokerEvents
|
||||
from amqtt.mqtt import MQTTPacket
|
||||
from amqtt.mqtt.packet import MQTTFixedHeader, MQTTPayload, MQTTVariableHeader
|
||||
from amqtt.plugins.base import BasePlugin
|
||||
|
@ -11,13 +12,17 @@ from amqtt.session import Session
|
|||
|
||||
PACKET: TypeAlias = MQTTPacket[MQTTVariableHeader, MQTTPayload[MQTTVariableHeader], MQTTFixedHeader]
|
||||
|
||||
|
||||
class EventLoggerPlugin(BasePlugin[BaseContext]):
|
||||
"""A plugin to log events dynamically based on method names."""
|
||||
|
||||
async def log_event(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""Log the occurrence of an event."""
|
||||
event_name = kwargs["event_name"].replace("old", "")
|
||||
self.context.logger.info(f"### '{event_name}' EVENT FIRED ###")
|
||||
if event_name.replace("on_", "") in (BrokerEvents.CLIENT_CONNECTED, BrokerEvents.CLIENT_DISCONNECTED):
|
||||
self.context.logger.info(f"### '{event_name}' EVENT FIRED ###")
|
||||
else:
|
||||
self.context.logger.debug(f"### '{event_name}' EVENT FIRED ###")
|
||||
|
||||
def __getattr__(self, name: str) -> Callable[..., Coroutine[Any, Any, None]]:
|
||||
"""Dynamically handle calls to methods starting with 'on_'."""
|
||||
|
|
Ładowanie…
Reference in New Issue