Commit a7396265 authored by Devaev Maxim's avatar Devaev Maxim

Added log coloring

parent 52014a4c
......@@ -25,7 +25,8 @@ ConfigDictObject = {
"service_name" : (const.DEFAULT_SERVICE_NAME, str),
"service_path" : (const.DEFAULT_SERVICE_PATH, str),
"bus_type" : (const.DEFAULT_BUS_TYPE, ( lambda arg : validators.validRange(arg, const.ALL_BUS_TYPES_LIST) )),
"log_level" : (const.DEFAULT_LOG_LEVEL, ( lambda arg : validators.validRange(int(arg), const.ALL_LOG_LEVELS_LIST) ))
"log_level" : (const.DEFAULT_LOG_LEVEL, ( lambda arg : validators.validRange(int(arg), const.ALL_LOG_LEVELS_LIST) )),
"log_use_colors" :(const.DEFAULT_LOG_USE_COLORS_FLAG, validators.validBool)
},
RUNTIME_SECTION : {
"bus_name" : (None, None),
......
......@@ -33,4 +33,5 @@ DEFAULT_SERVICE_NAME = "org.etersoft.%s" % (MY_NAME)
DEFAULT_SERVICE_PATH = "/org/etersoft/%s" % (MY_NAME)
DEFAULT_BUS_TYPE = BUS_TYPE_SYSTEM
DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO
DEFAULT_LOG_USE_COLORS_FLAG = True
......@@ -38,7 +38,15 @@ def log(message_type, message) :
raise UnknownMessageType("Message type \"%d\" not in list %s" % (message_type, ALL_MESSAGES_LIST))
if message_type[2] <= config.value(config.APPLICATION_SECTION, "log_level") :
message_type_texts_list = ("Error", "Warning", "Notice", "Info", "Details", "Debug")
use_colors_flag = sys.stderr.isatty() and config.value(config.APPLICATION_SECTION, "log_use_colors")
message_type_texts_list = (
( "\033[31mError\033[0m" if use_colors_flag else "Error" ),
( "\033[33mWarning\033[0m" if use_colors_flag else "Warning" ),
( "\033[32mNotice\033[0m" if use_colors_flag else "Notice" ),
( "\033[32mInfo\033[0m" if use_colors_flag else "Info" ),
( "\033[36mDetails\033[0m" if use_colors_flag else "Details" ),
"Debug"
)
message = "[ %s ]: %s" % (message_type_texts_list[message_type[0]], message)
print >> sys.stderr, const.MY_NAME, message
......
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