X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/b2d4a94dcd881e16c188b1efcb253f24873d8616..dc8216d3cd94fe2a5d89c6e8a4fae5de2f25bc9b:/src/app/log.py?ds=sidebyside diff --git a/src/app/log.py b/src/app/log.py index 457866b..f07e3d2 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -10,13 +10,49 @@ from events import TIMEOUT, COLOVER, eventNames from event_pprinters import pprinters import sys import pygame -from logging import basicConfig, getLogger, DEBUG - -basicConfig(level=DEBUG, stream = sys.stdout) -console = getLogger('minwii') -eventLog = getLogger('minwii.events') +import logging hiddenEvents = {pygame.MOUSEMOTION:True, + pygame.MOUSEBUTTONDOWN:True, + pygame.MOUSEBUTTONUP:True, TIMEOUT:True, #COLOVER:True, } + + +class EventLoggerAdapter(logging.LoggerAdapter) : + + FORMAT = "%(ticks)-10s %(eventName)-15s %(message)s" + + def process(self, msg, kwargs) : + pp = pprinters.get(msg.type, lambda e: str(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) +console.addHandler(logging.StreamHandler()) + +_eventLogger = logging.getLogger('minwii.events') +_eventLogger.setLevel(logging.INFO) +_eventHandler = logging.StreamHandler() +_eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) +_eventHandler.setFormatter(_eventFormatter) +_eventLogger.addHandler(_eventHandler) +_eventLogger.addFilter(EventFilter()) + +eventLogger = EventLoggerAdapter(_eventLogger, {}) +#eventLogger = logging.getLogger('minwii.events')