From b750263a0537d97f92dad452ef460ee6064af5f3 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Fri, 7 Oct 2016 13:40:09 -0400 Subject: [bug] fix logging on hooks --- src/leap/bitmask/hooks.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/leap/bitmask/hooks.py b/src/leap/bitmask/hooks.py index 79edf6c6..fb9771e9 100644 --- a/src/leap/bitmask/hooks.py +++ b/src/leap/bitmask/hooks.py @@ -20,11 +20,14 @@ Hooks for service composition. from collections import defaultdict from twisted.application.service import IService, Service -from twisted.python import log +from twisted.logger import Logger from zope.interface import implementer +logger = Logger() + + @implementer(IService) class HookableService(Service): @@ -44,7 +47,7 @@ class HookableService(Service): def register_hook(self, name, listener): if not hasattr(self, 'event_listeners'): self.event_listeners = defaultdict(list) - log.msg("Registering hook %s->%s" % (name, listener)) + logger.debug('registering hook %s->%s' % (name, listener)) self.event_listeners[name].append(listener) def trigger_hook(self, name, **data): @@ -53,11 +56,12 @@ class HookableService(Service): try: getattr(listener, 'hook_' + name)(**kw) except AttributeError as exc: + logger.failure('Error while triggering hook') raise RuntimeError( "Tried to notify a hook, but the listener " - "service class %s has not defined the " - "proper method %s" % - (listener.__class__, 'hook_' + name)) + "service class %s does not seem to have " + "defined the proper method: %s" + % (listener.__class__, 'hook_' + name)) if not hasattr(self, 'event_listeners'): self.event_listeners = defaultdict(list) -- cgit v1.2.3