diff --git a/hbmqtt/broker.py b/hbmqtt/broker.py index 733c769..0a437f4 100644 --- a/hbmqtt/broker.py +++ b/hbmqtt/broker.py @@ -115,7 +115,7 @@ class BrokerContext(BaseContext): It act as an adapter to broker services from plugins developed for HBMQTT broker """ def __init__(self, loop=None): - super().__init__(self, loop) + super().__init__(loop) class Broker: diff --git a/hbmqtt/plugins/__init__.py b/hbmqtt/plugins/__init__.py index e1bd617..395d1de 100644 --- a/hbmqtt/plugins/__init__.py +++ b/hbmqtt/plugins/__init__.py @@ -1 +1,5 @@ -__author__ = 'nico' +# Copyright (c) 2015 Nicolas JOUANIN +# +# See the file license.txt for copying permission. + +from .event_logger import EventLoggerPlugin \ No newline at end of file diff --git a/hbmqtt/plugins/event_logger.py b/hbmqtt/plugins/event_logger.py new file mode 100644 index 0000000..b10d83c --- /dev/null +++ b/hbmqtt/plugins/event_logger.py @@ -0,0 +1,21 @@ +# Copyright (c) 2015 Nicolas JOUANIN +# +# See the file license.txt for copying permission. + +import logging +import asyncio +from functools import partial + + +class EventLoggerPlugin: + def __init__(self, context): + self.logger = logging.getLogger(__name__) + self.context = context + + @asyncio.coroutine + def log_event(self, event_name): + self.logger.info("### EVENT FIRED: '%s' ###" % event_name) + + def __getattr__(self, name): + if name.startswith("on_"): + return partial(self.log_event, event_name=name) \ No newline at end of file diff --git a/setup.py b/setup.py index b2c8927..3f8f576 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,10 @@ setup( entry_points = { 'hbmqtt.test.plugins': [ 'test_plugin = tests.plugins.test_manager:TestPlugin', - 'event_plugin = tests.plugins.test_manager:EventTestPlugin' + 'event_plugin = tests.plugins.test_manager:EventTestPlugin', + ], + 'hbmqtt.broker': [ + 'event_logger_plugin = hbmqtt.plugins:EventLoggerPlugin', ] } ) \ No newline at end of file