From f930cbccef5ed34b7b17b9e738458b048d93d1da Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 16 Apr 2010 14:37:21 +0000 Subject: [PATCH 1/1] =?utf8?q?Filtrage=20des=20=C3=A9v=C3=A9nements=20au?= =?utf8?q?=20niveau=20avec=20l'api=20de=20logging=20python.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@147 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/eventutils.py | 5 ++--- src/app/log.py | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/app/eventutils.py b/src/app/eventutils.py index 9a7dd18..505455c 100755 --- a/src/app/eventutils.py +++ b/src/app/eventutils.py @@ -29,7 +29,7 @@ $URL$ import types import pygame from StringIO import StringIO -from log import console, eventLogger, hiddenEvents, pprinters +from log import console, eventLogger class _EventDispatcher : def __init__(self) : @@ -50,9 +50,8 @@ class _EventDispatcher : def dispatchEvents(self) : events = pygame.event.get() for event in events : + eventLogger.info(event) listeners = self.registry.get(event.type, {}) - if not hiddenEvents.has_key(event.type): - eventLogger.info(event) for listener in listeners.keys() : listener(event) diff --git a/src/app/log.py b/src/app/log.py index f270b8d..ca10200 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -12,19 +12,35 @@ import sys import pygame import logging +hiddenEvents = {pygame.MOUSEMOTION:True, + pygame.MOUSEBUTTONDOWN:True, + pygame.MOUSEBUTTONUP:True, + TIMEOUT:True, + #COLOVER:True, + } + class EventLoggerAdapter(logging.LoggerAdapter) : - FORMAT = "%(ticks)-15s %(eventName)s %(message)s" + FORMAT = "%(ticks)-10s %(eventName)-15s %(message)s" def process(self, msg, kwargs) : pp = pprinters.get(msg.type, lambda e: '') extra = {} + extra['eventType'] = msg.type extra['eventName'] = eventNames[msg.type] extra['ticks'] = pygame.time.get_ticks() kwargs['extra']=extra return pp(msg), kwargs +class EventFilter : + + def __init__(self): + pass + + def filter(self, record) : + return not hiddenEvents.has_key(record.eventType) + #logging.basicConfig(level=logging.DEBUG, stream = sys.stdout) console = logging.getLogger('minwii.console') console.setLevel(logging.DEBUG) @@ -36,10 +52,7 @@ _eventHandler = logging.StreamHandler() _eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) _eventHandler.setFormatter(_eventFormatter) _eventLogger.addHandler(_eventHandler) +_eventLogger.addFilter(EventFilter()) eventLogger = EventLoggerAdapter(_eventLogger, {}) -hiddenEvents = {pygame.MOUSEMOTION:True, - TIMEOUT:True, - #COLOVER:True, - } -- 2.20.1