X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/46f3ffd7fdde386f41020171b5733e55a8e64a85..refs/heads/master:/src/minwii/log.py?ds=sidebyside diff --git a/src/minwii/log.py b/src/minwii/log.py index abbb858..e612491 100755 --- a/src/minwii/log.py +++ b/src/minwii/log.py @@ -13,6 +13,7 @@ import pygame import logging import os import datetime +from config import LOGS_DIR as logsdir LOG_FORMAT_VERSION='1.0' hiddenEvents = {pygame.MOUSEMOTION:True, @@ -21,38 +22,40 @@ hiddenEvents = {pygame.MOUSEMOTION:True, #COLOVER:True, } -logsdir = os.path.join(os.path.expanduser('~'), 'minwii_logs') if not os.path.exists(logsdir) : os.mkdir(logsdir) - -class MinWiiStreamHandler(logging.StreamHandler) : - logfile = None - stream = None - env = [] +if os.environ.has_key('WINWII_NO_LOG') : + class MinWiiStreamHandler(logging.Handler) : + def emit(record) : pass +else : + class MinWiiStreamHandler(logging.StreamHandler) : + logfile = None + stream = None + env = [] - def __init__(self) : - logging.Handler.__init__(self) - if self.stream is None : - self.setNewStream() + 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') + @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) + 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) :