X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/blobdiff_plain/2feaf292e83d3c06e228ea81b4cd0a018d50de36..cf0a97e6fca3155000772d961bba89c215e1b457:/src/app/log.py?ds=sidebyside diff --git a/src/app/log.py b/src/app/log.py index f270b8d..e3a2182 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -11,35 +11,57 @@ from event_pprinters import pprinters import sys import pygame import logging +import os +import datetime +LOG_FORMAT_VERSION='1.0-alpha' +hiddenEvents = {pygame.MOUSEMOTION:True, + pygame.MOUSEBUTTONDOWN:True, + pygame.MOUSEBUTTONUP:True, + TIMEOUT:True, + #COLOVER:True, + } class EventLoggerAdapter(logging.LoggerAdapter) : - FORMAT = "%(ticks)-15s %(eventName)s %(message)s" + FORMAT = "EVT %(ticks)-10s %(eventName)-15s %(message)s" def process(self, msg, kwargs) : - pp = pprinters.get(msg.type, lambda e: '') + pp = pprinters.get(msg.type, lambda e: str(e)) extra = {} + extra['eventType'] = msg.type extra['eventName'] = eventNames[msg.type] extra['ticks'] = pygame.time.get_ticks() kwargs['extra']=extra return pp(msg), kwargs -#logging.basicConfig(level=logging.DEBUG, stream = sys.stdout) +class EventFilter : + + def __init__(self): + pass + + def filter(self, record) : + return not hiddenEvents.has_key(record.eventType) + +logsdir = os.path.join(os.path.expanduser('~'), 'minwii_logs') +if not os.path.exists(logsdir) : + os.mkdir(logsdir) + +logfile = os.path.join(logsdir, datetime.datetime.now().strftime('%Y-%m-%d-%H_%M_%S.log')) +logfile = open(logfile, 'w') + console = logging.getLogger('minwii.console') console.setLevel(logging.DEBUG) -console.addHandler(logging.StreamHandler()) +handler = logging.StreamHandler(logfile) +handler.setFormatter(logging.Formatter('APP %(message)s')) +console.addHandler(handler) _eventLogger = logging.getLogger('minwii.events') _eventLogger.setLevel(logging.INFO) -_eventHandler = logging.StreamHandler() +_eventHandler = logging.StreamHandler(logfile) _eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) _eventHandler.setFormatter(_eventFormatter) _eventLogger.addHandler(_eventHandler) +_eventLogger.addFilter(EventFilter()) eventLogger = EventLoggerAdapter(_eventLogger, {}) - -hiddenEvents = {pygame.MOUSEMOTION:True, - TIMEOUT:True, - #COLOVER:True, - }