00c371b687c425bde7eceebfbf494b5f3ede0309
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
17 hiddenEvents
= {pygame
.MOUSEMOTION
:True,
18 pygame
.MOUSEBUTTONDOWN
:True,
19 pygame
.MOUSEBUTTONUP
:True,
24 class EventLoggerAdapter(logging
.LoggerAdapter
) :
26 FORMAT
= "EVT %(ticks)-10s %(eventName)-15s %(message)s"
28 def process(self
, msg
, kwargs
) :
29 pp
= pprinters
.get(msg
.type, lambda e
: str(e
))
31 extra
['eventType'] = msg
.type
32 extra
['eventName'] = eventNames
[msg
.type]
33 extra
['ticks'] = pygame
.time
.get_ticks()
35 return pp(msg
), kwargs
42 def filter(self
, record
) :
43 return not hiddenEvents
.has_key(record
.eventType
)
45 logsdir
= os
.path
.join(os
.path
.expanduser('~'), 'minwii_logs')
46 if not os
.path
.exists(logsdir
) :
49 logfile
= os
.path
.join(logsdir
, datetime
.datetime
.now().strftime('%Y-%m-%d-%H_%M_%S.log'))
50 logfile
= open(logfile
, 'w')
52 console
= logging
.getLogger('minwii.console')
53 console
.setLevel(logging
.DEBUG
)
54 handler
= logging
.StreamHandler(logfile
)
55 handler
.setFormatter(logging
.Formatter('APP %(message)s'))
56 console
.addHandler(handler
)
58 _eventLogger
= logging
.getLogger('minwii.events')
59 _eventLogger
.setLevel(logging
.INFO
)
60 _eventHandler
= logging
.StreamHandler(logfile
)
61 _eventFormatter
= logging
.Formatter(EventLoggerAdapter
.FORMAT
)
62 _eventHandler
.setFormatter(_eventFormatter
)
63 _eventLogger
.addHandler(_eventHandler
)
64 _eventLogger
.addFilter(EventFilter())
66 eventLogger
= EventLoggerAdapter(_eventLogger
, {})