Commit eb90bcac authored by Devaev Maxim's avatar Devaev Maxim

New {submod} macros for logger

parent 76a73242
...@@ -28,6 +28,7 @@ ALL_MESSAGES_LIST = ( ...@@ -28,6 +28,7 @@ ALL_MESSAGES_LIST = (
DEBUG_MESSAGE DEBUG_MESSAGE
) )
ALL_MESSAGES_TEXTS_LIST = ( ALL_MESSAGES_TEXTS_LIST = (
(" Error ", "\033[31m Error \033[0m"), (" Error ", "\033[31m Error \033[0m"),
("Warning", "\033[33mWarning\033[0m"), ("Warning", "\033[33mWarning\033[0m"),
...@@ -37,9 +38,17 @@ ALL_MESSAGES_TEXTS_LIST = ( ...@@ -37,9 +38,17 @@ ALL_MESSAGES_TEXTS_LIST = (
(" Debug ", " Debug ") (" Debug ", " Debug ")
) )
MODULE_CALLER_NAME_TAG = "{mod}" MODULE_CALLER_NAME_TAG = "{mod}"
SUBMODULE_CALLER_NAME_TAG = "{submod}"
CURRENT_TIME_TAG = "{time}" CURRENT_TIME_TAG = "{time}"
ALL_TAGS_LIST = (
MODULE_CALLER_NAME_TAG,
SUBMODULE_CALLER_NAME_TAG,
CURRENT_TIME_TAG
)
##### Exceptions ##### ##### Exceptions #####
class UnknownMessageType(Exception) : class UnknownMessageType(Exception) :
...@@ -52,12 +61,19 @@ def log(message_type, message) : ...@@ -52,12 +61,19 @@ def log(message_type, message) :
raise UnknownMessageType("Message type \"%s\" not in list %s" % (str(message_type), ALL_MESSAGES_LIST)) raise UnknownMessageType("Message type \"%s\" not in list %s" % (str(message_type), ALL_MESSAGES_LIST))
if message_type[2] <= config.value(config.APPLICATION_SECTION, "log_level") : if message_type[2] <= config.value(config.APPLICATION_SECTION, "log_level") :
if MODULE_CALLER_NAME_TAG in message : for all_tags_list_item in ALL_TAGS_LIST :
try : if all_tags_list_item == MODULE_CALLER_NAME_TAG :
message = message.replace(MODULE_CALLER_NAME_TAG, inspect.getmodule(inspect.currentframe().f_back.f_back).__name__) try :
except : pass message = message.replace(MODULE_CALLER_NAME_TAG,
if CURRENT_TIME_TAG in message : inspect.getmodule(inspect.currentframe().f_back.f_back).__name__)
message = message.replace(CURRENT_TIME_TAG, time.ctime()) except : pass
elif all_tags_list_item == SUBMODULE_CALLER_NAME_TAG :
try :
message = message.replace(SUBMODULE_CALLER_NAME_TAG,
inspect.getmodule(inspect.currentframe().f_back.f_back.f_back).__name__)
except : pass
elif all_tags_list_item == CURRENT_TIME_TAG :
message = message.replace(CURRENT_TIME_TAG, time.ctime())
colored_index = int(sys.stderr.isatty() and config.value(config.APPLICATION_SECTION, "log_use_colors")) colored_index = int(sys.stderr.isatty() and config.value(config.APPLICATION_SECTION, "log_use_colors"))
for message_list_item in message.split("\n") : for message_list_item in message.split("\n") :
......
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