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) :
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)
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,