# -*- coding: utf-8 -*-
#
-# Copyright (C) 2008-2021 EDF R&D
+# Copyright (C) 2008-2024 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
import ExtendedLogging ; ExtendedLogging.ExtendedLogging(level=20)
On peut éventuellement demander à l'objet de sortir aussi les messages dans
- un fichier (noms par défaut : Aidsm.log, niveau NOTSET) :
+ un fichier (noms par défaut : AdaoOutputLogfile.log, niveau NOTSET) :
import ExtendedLogging ; ExtendedLogging.ExtendedLogging().setLogfile()
Si on veut changer le nom du fichier ou le niveau global de message, il faut
import time
from daCore import PlatformInfo
-LOGFILE = os.path.join(os.path.abspath(os.curdir),"AssimilationStudy.log")
+LOGFILE = os.path.join(os.path.abspath(os.curdir), "AdaoOutputLogfile.log")
# ==============================================================================
class ExtendedLogging(object):
Logger général pour disposer conjointement de la sortie standard et de la
sortie sur fichier
"""
+ __slots__ = ("__logfile")
+
def __init__(self, level=logging.WARNING):
"""
Initialise un logging à la console pour TOUS les niveaux de messages.
"""
- logging.basicConfig(
- format = '%(levelname)-8s %(message)s',
- level = level,
- stream = sys.stdout,
+ if sys.version_info.major <= 3 and sys.version_info.minor < 8:
+ if logging.getLogger().hasHandlers():
+ while logging.getLogger().hasHandlers():
+ logging.getLogger().removeHandler( logging.getLogger().handlers[-1] )
+ __sys_stdout = logging.StreamHandler(sys.stdout)
+ __sys_stdout.setFormatter(logging.Formatter('%(levelname)-8s %(message)s'))
+ logging.getLogger().addHandler(__sys_stdout)
+ else:
+ logging.basicConfig(
+ format = '%(levelname)-8s %(message)s',
+ level = level,
+ stream = sys.stdout,
+ )
+ else: # Actif lorsque Python > 3.7
+ logging.basicConfig(
+ format = '%(levelname)-8s %(message)s',
+ level = level,
+ stream = sys.stdout,
+ force = True,
)
self.__logfile = None
#
# Initialise l'affichage de logging
# ---------------------------------
- p = PlatformInfo.PlatformInfo()
+ lpi = PlatformInfo.PlatformInfo()
#
logging.info( "--------------------------------------------------" )
- logging.info( p.getName()+" version "+p.getVersion() )
+ logging.info( lpi.getName() + " version " + lpi.getVersion() )
logging.info( "--------------------------------------------------" )
logging.info( "Library availability:" )
logging.info( "- Python.......: True" )
- logging.info( "- Numpy........: True" )
- logging.info( "- Scipy........: "+str(PlatformInfo.has_scipy) )
- logging.info( "- Matplotlib...: "+str(PlatformInfo.has_matplotlib) )
- logging.info( "- Gnuplot......: "+str(PlatformInfo.has_scipy) )
- logging.info( "- Sphinx.......: "+str(PlatformInfo.has_sphinx) )
- logging.info( "- Nlopt........: "+str(PlatformInfo.has_nlopt) )
+ logging.info( "- Numpy........: " + str(lpi.has_numpy) )
+ logging.info( "- Scipy........: " + str(lpi.has_scipy) )
+ logging.info( "- Matplotlib...: " + str(lpi.has_matplotlib) )
+ logging.info( "- Gnuplot......: " + str(lpi.has_gnuplot) )
+ logging.info( "- Sphinx.......: " + str(lpi.has_sphinx) )
+ logging.info( "- Nlopt........: " + str(lpi.has_nlopt) )
logging.info( "Library versions:" )
- logging.info( "- Python.......: "+p.getPythonVersion() )
- logging.info( "- Numpy........: "+p.getNumpyVersion() )
- logging.info( "- Scipy........: "+p.getScipyVersion() )
+ logging.info( "- Python.......: " + lpi.getPythonVersion() )
+ logging.info( "- Numpy........: " + lpi.getNumpyVersion() )
+ logging.info( "- Scipy........: " + lpi.getScipyVersion() )
+ logging.info( "- Matplotlib...: " + lpi.getMatplotlibVersion() )
+ logging.info( "- Gnuplot......: " + lpi.getGnuplotVersion() )
+ logging.info( "- Sphinx.......: " + lpi.getSphinxVersion() )
+ logging.info( "- Nlopt........: " + lpi.getNloptVersion() )
logging.info( "" )
def setLogfile(self, filename=LOGFILE, filemode="w", level=logging.NOTSET):
Permet de disposer des messages dans un fichier EN PLUS de la console.
"""
if self.__logfile is not None:
- # Supprime le précédent mode de stockage fichier s'il exsitait
+ # Supprime le précédent mode de stockage fichier s'il existait
logging.getLogger().removeHandler(self.__logfile)
self.__logfile = logging.FileHandler(filename, filemode)
self.__logfile.setLevel(level)
def logtimer(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
- start = time.clock() # time.time()
+ start = time.clock() # time.time()
result = f(*args, **kwargs)
- end = time.clock() # time.time()
+ end = time.clock() # time.time()
msg = 'TIMER Durée elapsed de la fonction utilisateur "{}": {:.3f}s'
- logging.debug(msg.format(f.__name__, end-start))
+ logging.debug(msg.format(f.__name__, end - start))
return result
return wrapper
# ==============================================================================
if __name__ == "__main__":
- print('\n AUTODIAGNOSTIC\n')
+ print("\n AUTODIAGNOSTIC\n")