X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FTools%2FblocFissure%2Fgmu%2FinitLog.py;h=c665e5c75642c70002cd284cdec47c920764ac2c;hp=63908c1d054101ea46bfdeabaa85bd7563c570a2;hb=63d89b45fcdffeb46a091cc64e58f7d44b1b355f;hpb=5d68554076bbca0e1e95fb0db215a6c2b84b6c54 diff --git a/src/Tools/blocFissure/gmu/initLog.py b/src/Tools/blocFissure/gmu/initLog.py index 63908c1d0..c665e5c75 100644 --- a/src/Tools/blocFissure/gmu/initLog.py +++ b/src/Tools/blocFissure/gmu/initLog.py @@ -1,28 +1,121 @@ # -*- coding: utf-8 -*- +# Copyright (C) 2014-2021 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +"""Initialisations des impressions""" import logging +import os +import tempfile -def setDebug(): - logging.basicConfig(format='%(relativeCreated)d %(funcName)s[%(lineno)d] %(message)s', - level=logging.DEBUG) - logging.info('start Debug') - -def setVerbose(): - logging.basicConfig(format='%(relativeCreated)d %(funcName)s[%(lineno)d] %(message)s', - level=logging.INFO) - logging.info('start Verbose') - -def setRelease(): - logging.basicConfig(format='%(funcName)s[%(lineno)d] %(message)s', - level=logging.WARNING) - logging.warning('start Release') - -def setUnitTests(): - logging.basicConfig(format='%(funcName)s[%(lineno)d] %(message)s', - level=logging.CRITICAL) - logging.critical('start UnitTests') - - #logging.basicConfig(filename='myapp.log', - # format='%(asctime)s %(message)s', - # datefmt='%m/%d/%Y %I:%M:%S %p', - # level=logging.DEBUG) +debug = 10 +info = 20 +warning = 30 +error = 40 +critical = 50 +always = 100 + +LOGFILE = tempfile.NamedTemporaryFile().name + "_blocFissure.log" + +LOG_LEVEL = warning + +logging.basicConfig(format='%(funcName)s[%(lineno)d] %(message)s', \ + level=logging.WARNING, \ + filename=LOGFILE, filemode='w') +ch = None +fh = None + +def setLogger(logfile, level, formatter): + """setLogger""" + global ch, fh + rootLogger = logging.getLogger('') + if fh is not None: + rootLogger.removeHandler(fh) + fh = None + if ch is not None: + rootLogger.removeHandler(ch) + ch = None + if logfile: + if os.path.exists(logfile): + os.remove(logfile) + fh = logging.FileHandler(logfile) + rootLogger.addHandler(fh) + fh.setFormatter(formatter) + else: + ch = logging.StreamHandler() + rootLogger.addHandler(ch) + ch.setFormatter(formatter) + rootLogger.setLevel(level) + +def setDebug(logfile=None): + """setDebug""" + global LOG_LEVEL + LOG_LEVEL = debug + level = logging.DEBUG + formatter = logging.Formatter('%(relativeCreated)d %(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.info('start Debug %s', LOG_LEVEL) + +def setVerbose(logfile=None): + """setVerbose""" + global LOG_LEVEL + LOG_LEVEL = info + level = logging.INFO + formatter = logging.Formatter('%(relativeCreated)d %(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.info('start Verbose %s', LOG_LEVEL) + +def setRelease(logfile=None): + """setRelease""" + global LOG_LEVEL + LOG_LEVEL = warning + level = logging.WARNING + formatter = logging.Formatter('%(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.warning('start Release %s', LOG_LEVEL) + +def setUnitTests(logfile=None): + """setUnitTests""" + global LOG_LEVEL + LOG_LEVEL = critical + level = logging.CRITICAL + formatter = logging.Formatter('%(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.critical('start UnitTests %s', LOG_LEVEL) + +def setPerfTests(logfile=None): + """setPerfTests""" + global LOG_LEVEL + LOG_LEVEL = critical + level = logging.CRITICAL + formatter = logging.Formatter('%(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.info('start PerfTests %s', LOG_LEVEL) + +def setAlways(logfile=None): + """setAlways""" + global LOG_LEVEL + LOG_LEVEL = always + level = logging.CRITICAL + formatter = logging.Formatter('%(relativeCreated)d %(funcName)s[%(lineno)d] %(message)s') + setLogger(logfile, level, formatter) + logging.info('start Always %s', LOG_LEVEL) + +def getLogLevel(): + """getLogLevel""" + return LOG_LEVEL