b2cd407ecc0ef0306710f317232a1dd42952cd90
[minwii.git] / src / app / log.py
1 # -*- coding: utf-8 -*-
2 """
3 utilitaires pour tracer l'activité de miiwii
4
5 $Id$
6 $URL$
7 """
8
9 from events import TIMEOUT, COLOVER, eventNames
10 from event_pprinters import pprinters
11 import sys
12 import pygame
13 import logging
14
15
16 class EventLoggerAdapter(logging.LoggerAdapter) :
17
18 FORMAT = "%(ticks)-15s %(eventName)s %(message)s"
19
20 def process(self, msg, kwargs) :
21 pp = pprinters.get(msg.type, lambda e: '')
22 extra = {}
23 extra['eventName'] = eventNames[msg.type]
24 extra['ticks'] = pygame.time.get_ticks()
25 kwargs['extra']=extra
26 return pp(msg), kwargs
27
28 #logging.basicConfig(level=logging.DEBUG, stream = sys.stdout)
29
30 console = logging.getLogger('minwii.console')
31 _eventLogger = logging.getLogger('minwii.events')
32 _eventLogger.setLevel(logging.INFO)
33 _eventHandler = logging.StreamHandler()
34 _eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT)
35 _eventHandler.setFormatter(_eventFormatter)
36 _eventLogger.addHandler(_eventHandler)
37
38 eventLogger = EventLoggerAdapter(_eventLogger, {})
39
40 hiddenEvents = {pygame.MOUSEMOTION:True,
41 TIMEOUT:True,
42 #COLOVER:True,
43 }