def getLevelName(level):
"""
Return the textual representation of logging level 'level'.
If the level is one of the predefined levels (CRITICAL, ERROR, WARNING,
INFO, DEBUG) then you get the corresponding string. If you have
associated levels with names using addLevelName then the name you have
associated with 'level' is returned.
If a numeric value corresponding to one of the defined levels is passed
in, the corresponding string representation is returned.
Otherwise, the string "Level %s" % level is returned.
"""
return _levelNames.get(level, ("Level %s" % level))
def addLevelName(level, levelName):
"""
Associate 'levelName' with 'level'.
This is used when converting levels to text during message formatting.
"""
_acquireLock()
try: #unlikely to cause an exception, but you never know...
_levelNames[level] = levelName
_levelNames[levelName] = level
finally:
_releaseLock()
Je trouve ça moche et inefficace. Voici donc un exemple précis ou les symboles simplifient la vie et la clarté. Et c'est à cause de ce genre de détails que je préfère Ruby à Python.
[^] # Re: A quand l'équivalent des symboles Ruby en Python ?
Posté par totof2000 . En réponse à la dépêche Python 3.4 est sorti avec 7 nouveaux modules. Évalué à 3. Dernière modification le 19 mars 2014 à 14:50.
Je viens d'aller voir le module logger, et comme je le craignais, on a un truc affreux comme ça :
avec plus loin ceci :
Je trouve ça moche et inefficace. Voici donc un exemple précis ou les symboles simplifient la vie et la clarté. Et c'est à cause de ce genre de détails que je préfère Ruby à Python.