From e6ef7fb704667d8266e6d881ff5e39be0e4188fa Mon Sep 17 00:00:00 2001 From: pin Date: Fri, 16 Apr 2010 09:55:06 +0000 Subject: [PATCH 1/1] =?utf8?q?le=20logging=20commence=20=C3=A0=20avoir=20u?= =?utf8?q?ne=20bonne=20t=C3=AAte.?= 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@143 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/event_pprinters.py | 1 + src/app/eventutils.py | 5 ++--- src/app/log.py | 29 +++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/app/event_pprinters.py b/src/app/event_pprinters.py index 0f56915..199ef27 100755 --- a/src/app/event_pprinters.py +++ b/src/app/event_pprinters.py @@ -18,6 +18,7 @@ def log_COLSTATECHANGE(e) : return u'%5s %s' % (e.state, e.syllabus) def log_default(e) : + return '' return str(e) pprinters = {} diff --git a/src/app/eventutils.py b/src/app/eventutils.py index c0aada5..9a7dd18 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, eventLog, hiddenEvents, pprinters +from log import console, eventLogger, hiddenEvents, pprinters class _EventDispatcher : def __init__(self) : @@ -52,8 +52,7 @@ class _EventDispatcher : for event in events : listeners = self.registry.get(event.type, {}) if not hiddenEvents.has_key(event.type): - #if listeners and not hiddenEvents.has_key(event.type) : - eventLog.info(pprinters[event.type](event)) + eventLogger.info(event) for listener in listeners.keys() : listener(event) diff --git a/src/app/log.py b/src/app/log.py index 457866b..b2cd407 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -10,11 +10,32 @@ from events import TIMEOUT, COLOVER, eventNames from event_pprinters import pprinters import sys import pygame -from logging import basicConfig, getLogger, DEBUG +import logging -basicConfig(level=DEBUG, stream = sys.stdout) -console = getLogger('minwii') -eventLog = getLogger('minwii.events') + +class EventLoggerAdapter(logging.LoggerAdapter) : + + FORMAT = "%(ticks)-15s %(eventName)s %(message)s" + + def process(self, msg, kwargs) : + pp = pprinters.get(msg.type, lambda e: '') + extra = {} + extra['eventName'] = eventNames[msg.type] + extra['ticks'] = pygame.time.get_ticks() + kwargs['extra']=extra + return pp(msg), kwargs + +#logging.basicConfig(level=logging.DEBUG, stream = sys.stdout) + +console = logging.getLogger('minwii.console') +_eventLogger = logging.getLogger('minwii.events') +_eventLogger.setLevel(logging.INFO) +_eventHandler = logging.StreamHandler() +_eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) +_eventHandler.setFormatter(_eventFormatter) +_eventLogger.addHandler(_eventHandler) + +eventLogger = EventLoggerAdapter(_eventLogger, {}) hiddenEvents = {pygame.MOUSEMOTION:True, TIMEOUT:True, -- 2.20.1