X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/dc8216d3cd94fe2a5d89c6e8a4fae5de2f25bc9b..972649bb3a4feb51c6073c99ad10a82d50786717:/src/app/log.py?ds=sidebyside diff --git a/src/app/log.py b/src/app/log.py index f07e3d2..00c371b 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -11,6 +11,8 @@ from event_pprinters import pprinters import sys import pygame import logging +import os +import datetime hiddenEvents = {pygame.MOUSEMOTION:True, pygame.MOUSEBUTTONDOWN:True, @@ -19,10 +21,9 @@ hiddenEvents = {pygame.MOUSEMOTION:True, #COLOVER:True, } - class EventLoggerAdapter(logging.LoggerAdapter) : - FORMAT = "%(ticks)-10s %(eventName)-15s %(message)s" + FORMAT = "EVT %(ticks)-10s %(eventName)-15s %(message)s" def process(self, msg, kwargs) : pp = pprinters.get(msg.type, lambda e: str(e)) @@ -41,18 +42,25 @@ class EventFilter : def filter(self, record) : return not hiddenEvents.has_key(record.eventType) -#logging.basicConfig(level=logging.DEBUG, stream = sys.stdout) +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, {}) -#eventLogger = logging.getLogger('minwii.events')