From: pin Date: Tue, 20 Apr 2010 13:33:24 +0000 (+0000) Subject: découpage des fichiers de log par chansons jouées. X-Git-Url: https://scm.cri.mines-paristech.fr/git/minwii.git/commitdiff_plain/899a6365838f7a7c1427676277ef72c934c1d1bb découpage des fichiers de log par chansons jouées. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@157 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/app/log.py b/src/app/log.py index e3a2182..725abac 100755 --- a/src/app/log.py +++ b/src/app/log.py @@ -22,6 +22,42 @@ hiddenEvents = {pygame.MOUSEMOTION:True, #COLOVER:True, } +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') + + +class MinWiiStreamHandler(logging.StreamHandler) : + logfile = None + stream = None + env = [] + + def __init__(self) : + logging.Handler.__init__(self) + if self.stream is None : + self.setNewStream() + + @classmethod + def setNewStream(cls) : + if cls.stream and not cls.stream.closed : + cls.stream.close() + logfile = os.path.join(logsdir, datetime.datetime.now().strftime('%Y-%m-%d-%H_%M_%S.log')) + cls.stream = open(logfile, 'a') + + def emit(self, record) : + if record.name == 'minwii.env' : + if record.getMessage()=='NEW_LOG_FILE' : + self.setNewStream() + for rec in self.env : + logging.StreamHandler.emit(self, rec) + return + else : + self.env.append(record) + logging.StreamHandler.emit(self, record) + class EventLoggerAdapter(logging.LoggerAdapter) : FORMAT = "EVT %(ticks)-10s %(eventName)-15s %(message)s" @@ -43,25 +79,38 @@ class EventFilter : 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') +def initAppConsole() : + global console + console = logging.getLogger('minwii.console') + console.setLevel(logging.DEBUG) + handler = MinWiiStreamHandler() + handler.setFormatter(logging.Formatter('APP %(message)s')) + console.addHandler(handler) + +def initEnvLogger() : + global envLogger + envLogger = logging.getLogger('minwii.env') + envLogger.setLevel(logging.DEBUG) + handler = MinWiiStreamHandler() + handler.setFormatter(logging.Formatter('ENV %(message)s')) + envLogger.addHandler(handler) + -console = logging.getLogger('minwii.console') -console.setLevel(logging.DEBUG) -handler = logging.StreamHandler(logfile) -handler.setFormatter(logging.Formatter('APP %(message)s')) -console.addHandler(handler) +def initEventLogger(): + _eventLogger = logging.getLogger('minwii.events') + _eventLogger.setLevel(logging.INFO) + _eventHandler = MinWiiStreamHandler() + _eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) + _eventHandler.setFormatter(_eventFormatter) + _eventLogger.addHandler(_eventHandler) + _eventLogger.addFilter(EventFilter()) + global eventLogger + eventLogger = EventLoggerAdapter(_eventLogger, {}) -_eventLogger = logging.getLogger('minwii.events') -_eventLogger.setLevel(logging.INFO) -_eventHandler = logging.StreamHandler(logfile) -_eventFormatter = logging.Formatter(EventLoggerAdapter.FORMAT) -_eventHandler.setFormatter(_eventFormatter) -_eventLogger.addHandler(_eventHandler) -_eventLogger.addFilter(EventFilter()) +def initLoggers() : + initAppConsole() + initEnvLogger() + initEventLogger() -eventLogger = EventLoggerAdapter(_eventLogger, {}) +initLoggers() diff --git a/src/app/minwii.py b/src/app/minwii.py index a0a9161..2475d66 100755 --- a/src/app/minwii.py +++ b/src/app/minwii.py @@ -18,21 +18,22 @@ from eventutils import EventDispatcher from musicxml import musicXml2Song from config import SONG_FILE_PATH from globals import PLAYING_MODES_DICT -from log import console, LOG_FORMAT_VERSION +from log import console, LOG_FORMAT_VERSION, envLogger class MinWii(object): def __init__(self, wiimoteSupport=True) : - console.info('winwii log format version : %s', LOG_FORMAT_VERSION) + envLogger.info('winwii log format version : %s', LOG_FORMAT_VERSION) self.wiimoteSupport = wiimoteSupport LaunchScreen() self.app = Desktop() self.synth = Synth() self.screenResolution = (1024,768) - console.info('résolution écran : %s', self.screenResolution) + envLogger.info('résolution écran : %s', self.screenResolution) self.nwiimotes = 0 self.initWiimotes() + self.firstSong = True def initWiimotes(self) : if self.wiimoteSupport : @@ -89,6 +90,10 @@ class MinWii(object): console.info("sortie de l'application") else : actual_wiimotes = self.WT.get_count() + if self.firstSong : + self.firstSong = False + else : + envLogger.info('NEW_LOG_FILE') console.info('chanson : %s', home.songFile) console.info('mode : %s', home.modeSelect.value) if actual_wiimotes is None : diff --git a/src/app/synth.py b/src/app/synth.py index 1910643..eb19235 100755 --- a/src/app/synth.py +++ b/src/app/synth.py @@ -7,7 +7,7 @@ $URL$ """ from os.path import realpath, sep, exists from fluidsynth import Synth as FSynth -from log import console +from log import console, envLogger import pygame import events @@ -36,7 +36,7 @@ class Synth(FSynth) : self.fsid = self.sfload(sfPath) self._octaveAjusts = {} console.info('démarrage du synthétiseur') - console.info('soundfont : %s', sfPath) + envLogger.info('soundfont : %s', sfPath) def __del__(self) : console.info('arrêt du synthétiseur')