ca1020045de6bb3a872745cb831229541a383fa0
1 # -*- coding: utf-8 -*-
3 utilitaires pour tracer l'activité de miiwii
9 from events
import TIMEOUT
, COLOVER
, eventNames
10 from event_pprinters
import pprinters
15 hiddenEvents
= {pygame
.MOUSEMOTION
:True,
16 pygame
.MOUSEBUTTONDOWN
:True,
17 pygame
.MOUSEBUTTONUP
:True,
23 class EventLoggerAdapter(logging
.LoggerAdapter
) :
25 FORMAT
= "%(ticks)-10s %(eventName)-15s %(message)s"
27 def process(self
, msg
, kwargs
) :
28 pp
= pprinters
.get(msg
.type, lambda e
: '')
30 extra
['eventType'] = msg
.type
31 extra
['eventName'] = eventNames
[msg
.type]
32 extra
['ticks'] = pygame
.time
.get_ticks()
34 return pp(msg
), kwargs
41 def filter(self
, record
) :
42 return not hiddenEvents
.has_key(record
.eventType
)
44 #logging.basicConfig(level=logging.DEBUG, stream = sys.stdout)
45 console
= logging
.getLogger('minwii.console')
46 console
.setLevel(logging
.DEBUG
)
47 console
.addHandler(logging
.StreamHandler())
49 _eventLogger
= logging
.getLogger('minwii.events')
50 _eventLogger
.setLevel(logging
.INFO
)
51 _eventHandler
= logging
.StreamHandler()
52 _eventFormatter
= logging
.Formatter(EventLoggerAdapter
.FORMAT
)
53 _eventHandler
.setFormatter(_eventFormatter
)
54 _eventLogger
.addHandler(_eventHandler
)
55 _eventLogger
.addFilter(EventFilter())
57 eventLogger
= EventLoggerAdapter(_eventLogger
, {})