Add EventLoggingModule

pull/8/head
Nicolas Jouanin 2015-08-17 21:52:00 +02:00
rodzic e44c0b32df
commit 848aaf8438
4 zmienionych plików z 31 dodań i 3 usunięć

Wyświetl plik

@ -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:

Wyświetl plik

@ -1 +1,5 @@
__author__ = 'nico'
# Copyright (c) 2015 Nicolas JOUANIN
#
# See the file license.txt for copying permission.
from .event_logger import EventLoggerPlugin

Wyświetl plik

@ -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)

Wyświetl plik

@ -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',
]
}
)