You need to sign in or sign up before continuing.
Commit e61626a3 authored by Devaev Maxim's avatar Devaev Maxim

Fixed bug with method decorator, added logging for exceptions

parent 05f2c1b7
...@@ -31,12 +31,12 @@ class Application(object) : ...@@ -31,12 +31,12 @@ class Application(object) :
def exec_(self) : def exec_(self) :
self.init() self.init()
logger.message(const.LOG_LEVEL_INFO, "Initialized") logger.message(logger.INFO_MESSAGE, "Initialized")
try : try :
self.run() self.run()
except KeyboardInterrupt : except KeyboardInterrupt :
self.close() self.close()
logger.message(const.LOG_LEVEL_INFO, "Closed") logger.message(logger.INFO_MESSAGE, "Closed")
### Private ### ### Private ###
...@@ -60,7 +60,12 @@ class Application(object) : ...@@ -60,7 +60,12 @@ class Application(object) :
for modules_path_list_item in (const.FUNCTIONS_DIR, const.ACTIONS_DIR) : for modules_path_list_item in (const.FUNCTIONS_DIR, const.ACTIONS_DIR) :
for module_name in [ item[:-3] for item in os.listdir(modules_path_list_item) if item.endswith(".py") ] : for module_name in [ item[:-3] for item in os.listdir(modules_path_list_item) if item.endswith(".py") ] :
self._modules_list.append(__import__(module_name, globals(), locals(), [""])) try :
self._modules_list.append(__import__(module_name, globals(), locals(), [""]))
except Exception :
logger.message(logger.ERROR_MESSAGE, "Import error on module \"%s\"" % (module_name))
logger.attachException()
continue
self._services_dict[self._modules_list[-1].Service.serviceName()] = { self._services_dict[self._modules_list[-1].Service.serviceName()] = {
"service_class" : self._modules_list[-1].Service, "service_class" : self._modules_list[-1].Service,
"service" : None "service" : None
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import sys import sys
import traceback
import const import const
import config import config
...@@ -29,20 +30,24 @@ class UnknownMessageType(Exception) : ...@@ -29,20 +30,24 @@ class UnknownMessageType(Exception) :
##### Public methods ##### ##### Public methods #####
def message(message_type, message) : def message(message_type, message) :
if message_type in (ERROR_MESSAGE, INFO_MESSAGE) : if message_type in (ERROR_MESSAGE, INFO_MESSAGE) :
log_level = const.LOG_LEVEL_INFO message_level = const.LOG_LEVEL_INFO
elif message_type == VERBOSE_MESSAGE : elif message_type == VERBOSE_MESSAGE :
log_level = const.LOG_LEVEL_VERBOSE message_level = const.LOG_LEVEL_VERBOSE
elif message_type == DEBUG_MESSAGE : elif message_type == DEBUG_MESSAGE :
log_level = const.LOG_LEVEL_DEBUG message_level = const.LOG_LEVEL_DEBUG
else : else :
raise UnknownMessageType("Message type \"%d\" not in list %s" % (message_type, ALL_MESSAGES_LIST)) raise UnknownMessageType("Message type \"%d\" not in list %s" % (message_type, ALL_MESSAGES_LIST))
if log_level <= config.value(const.MY_NAME, "log_level") : if message_level <= config.value(const.MY_NAME, "log_level") :
text_log_levels_list = ( message_level_prefixes_list = (
"%s [ Error ]:" % (const.MY_NAME),
"%s [ Info ]:" % (const.MY_NAME), "%s [ Info ]:" % (const.MY_NAME),
"%s [ Details ]:" % (const.MY_NAME), "%s [ Details ]:" % (const.MY_NAME),
"%s [ Debug ]:" % (const.MY_NAME) "%s [ Debug ]:" % (const.MY_NAME)
) )
print >> sys.stderr, message_level_prefixes_list[message_type], message
print >> sys.stderr, text_log_levels_list[log_level], message def attachException() :
for line in traceback.format_exc().splitlines() :
message(ERROR_MESSAGE, line)
...@@ -89,7 +89,7 @@ def tracer(function) : ...@@ -89,7 +89,7 @@ def tracer(function) :
wrapper.__name__ = function.__name__ wrapper.__name__ = function.__name__
wrapper.__dict__ = function.__dict__ wrapper.__dict__ = function.__dict__
wrapper.__doc__ = functions.__doc__ wrapper.__doc__ = function.__doc__
return wrapper return wrapper
......
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