From: Christian Van Wambeke Date: Tue, 19 Jun 2018 11:53:07 +0000 (+0200) Subject: add known levels str in loggingSat.py X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b1d79b90bffe80e09a2df9a337b7ca2caebd5230;p=tools%2Fsat.git add known levels str in loggingSat.py --- diff --git a/src/loggingSat.py b/src/loggingSat.py index b70a94c..e925422 100755 --- a/src/loggingSat.py +++ b/src/loggingSat.py @@ -67,11 +67,33 @@ LOGI.STEP = _STEP # only for coherency, LOGI.TRACE = _TRACE # only for coherency, _knownLevels = "CRITICAL ERROR WARNING INFO STEP TRACE DEBUG".upper().split() +_knownLevelsStr = "[%s]" % "|".join(_knownLevels) ################################################################# # utilities methods ################################################################# +def filterLevel(aLevel): + """ + filter levels logging values from firsts characters levels. + No case sensitive + + | example: + | 'i' -> 'INFO' + | 'cRiT' -> 'CRITICAL' + """ + aLev = aLevel.upper() + knownLevels = _knownLevels + maxLen = max([len(i) for i in knownLevels]) + for i in range(maxLen): + for lev in knownLevels: + if aLev == lev[:i]: + # DBG.write("filterLevel", "%s -> %s" % (aLevel, lev)) + return lev + msg = "Unknown level '%s', accepted are:\n%s" % (aLev, ", ".join(knownLevels)) + return msg + #raise Exception(msg) + def indent(msg, nb, car=" "): """indent nb car (spaces) multi lines message except first one""" s = msg.split("\n")