Commit 6c1c5923 authored by Devaev Maxim's avatar Devaev Maxim

Added some types of messaging, optimized trace decorator

parent 50bcafea
......@@ -8,13 +8,41 @@ import config
#####
def message(log_level, message) :
text_log_levels_list = [
"%s [ Info ]:" % (const.MY_NAME), # const.LOG_LEVEL_INFO == 0
"%s [ Details ]:" % (const.MY_NAME), # const.LOG_LEVEL_VERBOSE == 1
"%s [ Debug ]:" % (const.MY_NAME) # # const.LOG_LEVEL_DEBUG == 2
]
ERROR_MESSAGE = 0
INFO_MESSAGE = 1
VERBOSE_MESSAGE = 2
DEBUG_MESSAGE = 3
ALL_MESSAGES_LIST = (
ERROR_MESSAGE,
INFO_MESSAGE,
VERBOSE_MESSAGE,
DEBUG_MESSAGE
)
#####
class UnknownMessageType(Exception) :
pass
#####
def message(message_type, message) :
if message_type in (ERROR_MESSAGE, INFO_MESSAGE) :
log_level = const.LOG_LEVEL_INFO
elif message_type == VERBOSE_MESSAGE :
log_level = const.LOG_LEVEL_VERBOSE
elif message_type == DEBUG_MESSAGE :
log_level = const.LOG_LEVEL_DEBUG
else :
raise UnknownMessageType("Message type \"%d\" not in list %s" % (message_type, ALL_MESSAGES_LIST))
if log_level <= config.value("service", "log_level") :
text_log_levels_list = (
"%s [ Info ]:" % (const.MY_NAME),
"%s [ Details ]:" % (const.MY_NAME),
"%s [ Debug ]:" % (const.MY_NAME)
)
print >> sys.stderr, text_log_levels_list[log_level], message
......@@ -62,8 +62,9 @@ class ActionObject(CustomObject) :
def tracer(function) :
def wrapper(self, *args_list, **kwargs_dict) :
return_value = function(self, *args_list, **kwargs_dict)
logger.message(const.LOG_LEVEL_DEBUG, "Called \"%s::%s\" with args (%s, %s) --> %s" % (
self.__class__.__name__, function.__name__, str(args_list), str(kwargs_dict), str(return_value) ))
if config.value("service", "log_level") == const.LOG_LEVEL_DEBUG :
logger.message(logger.DEBUG_MESSAGE, "Called \"%s::%s\" with args (%s, %s) --> %s" % (
self.__class__.__name__, function.__name__, str(args_list), str(kwargs_dict), str(return_value) ))
return return_value
wrapper.__dict__ = function.__dict__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment