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 ...@@ -8,13 +8,41 @@ import config
##### #####
def message(log_level, message) : ERROR_MESSAGE = 0
text_log_levels_list = [ INFO_MESSAGE = 1
"%s [ Info ]:" % (const.MY_NAME), # const.LOG_LEVEL_INFO == 0 VERBOSE_MESSAGE = 2
"%s [ Details ]:" % (const.MY_NAME), # const.LOG_LEVEL_VERBOSE == 1 DEBUG_MESSAGE = 3
"%s [ Debug ]:" % (const.MY_NAME) # # const.LOG_LEVEL_DEBUG == 2
] 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") : 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 print >> sys.stderr, text_log_levels_list[log_level], message
...@@ -62,7 +62,8 @@ class ActionObject(CustomObject) : ...@@ -62,7 +62,8 @@ class ActionObject(CustomObject) :
def tracer(function) : def tracer(function) :
def wrapper(self, *args_list, **kwargs_dict) : def wrapper(self, *args_list, **kwargs_dict) :
return_value = function(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" % ( 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) )) self.__class__.__name__, function.__name__, str(args_list), str(kwargs_dict), str(return_value) ))
return return_value return return_value
......
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