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
= "EVT %(ticks)-10s %(eventName)-15s %(message)s"
27 def process(self
, msg
, kwargs
) :
28 pp
= pprinters
.get(msg
.type, lambda e
: str(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 handler
= logging
.StreamHandler()
48 handler
.setFormatter(logging
.Formatter('APP %(message)s'))
49 console
.addHandler(handler
)
51 _eventLogger
= logging
.getLogger('minwii.events')
52 _eventLogger
.setLevel(logging
.INFO
)
53 _eventHandler
= logging
.StreamHandler()
54 _eventFormatter
= logging
.Formatter(EventLoggerAdapter
.FORMAT
)
55 _eventHandler
.setFormatter(_eventFormatter
)
56 _eventLogger
.addHandler(_eventHandler
)
57 _eventLogger
.addFilter(EventFilter())
59 eventLogger
= EventLoggerAdapter(_eventLogger
, {})
60 #eventLogger = logging.getLogger('minwii.events')