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