From acd9ed455dd78c8248b105d80361a5bf07efa094 Mon Sep 17 00:00:00 2001 From: pin Date: Mon, 19 Apr 2010 15:50:53 +0000 Subject: [PATCH] =?utf8?q?log=20dans=20un=20fichier=20horodat=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@153 fe552daf-6dbe-4428-90eb-1537e0879342 --- src/app/log.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/log.py b/src/app/log.py index c1e3286..74500ec 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,7 +21,6 @@ hiddenEvents = {pygame.MOUSEMOTION:True, #COLOVER:True, } - class EventLoggerAdapter(logging.LoggerAdapter) : FORMAT = "EVT %(ticks)-10s %(eventName)-15s %(message)s" @@ -41,20 +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.expandvars('$HOME'), '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) -handler = 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') -- 2.20.1