From 10f22fb1e88608ea5dced5c04ba58c36dec75a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Wed, 12 Dec 2012 12:18:55 +0000 Subject: [PATCH] Advancing logging --- server/src/uds/core/util/Log.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/src/uds/core/util/Log.py b/server/src/uds/core/util/Log.py index 8454fe3a..2372a46b 100644 --- a/server/src/uds/core/util/Log.py +++ b/server/src/uds/core/util/Log.py @@ -36,6 +36,34 @@ import logging logger = logging.getLogger(__name__) useLogger = logging.getLogger('useLog') +# Logging levels +OTHER,DEBUG,INFO,WARN,ERROR,FATAL = (10000*(x+1) for x in xrange(6)) + +# Logging sources +INTERNAL,ACTOR,TRANSPORT = ('internal', 'actor', 'transport') + +# Names for defined log levels +__nameLevels = { + 'DEBUG': DEBUG, + 'INFO': INFO, + 'WARN': WARN, + 'ERROR': ERROR, + 'FATAL': FATAL, + 'OTHER': OTHER + } + +# Reverse dict of names +__valueLevels = dict((v,k) for k, v in __nameLevels.iteritems()) + +def logLevelFromStr(str): + ''' + Gets the numeric log level from an string. + ''' + return __nameLevels.get(str, OTHER) + +def logStrFromLevel(level): + return __valueLevels.get(level, 'OTHER') + def useLog(type_, serviceUniqueId, serviceIp, username): useLogger.info('|'.join([type_, serviceUniqueId, serviceIp, username]))