diff --git a/opendm/log.py b/opendm/log.py index 7ab2badb..f5cd2095 100644 --- a/opendm/log.py +++ b/opendm/log.py @@ -1,3 +1,5 @@ +import logging + HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' @@ -5,18 +7,29 @@ WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' +# TODO add file handling + +logging.addLevelName(logging.INFO, '%s[%s]' % (OKBLUE, logging.getLevelName(logging.INFO))) +logging.addLevelName(logging.WARNING, '%s[%s]' % (WARNING, logging.getLevelName(logging.WARNING))) +logging.addLevelName(logging.ERROR, '%s[%s]' % (FAIL, logging.getLevelName(logging.ERROR))) +logging.addLevelName(logging.DEBUG, '%s[%s]' % (OKGREEN, logging.getLevelName(logging.DEBUG))) + +logging.basicConfig(level=logging.DEBUG, + format='%(levelname)-14s %(message)s' + ENDC) + def ODM_INFO(str): - print OKBLUE + '[INFO] ' + str + ENDC + logging.info(str) def ODM_WARNING(str): - print WARNING + '[WARNING] ' + str + ENDC + logging.warning(str) def ODM_ERROR(str): - print FAIL + '[ERROR] ' + str + ENDC + logging.error(str) def ODM_DEBUG(str): - print OKGREEN + '[DEBUG] ' + str + ENDC + logging.debug(str) + diff --git a/opendm/system.py b/opendm/system.py index 6da38e33..955c78c8 100644 --- a/opendm/system.py +++ b/opendm/system.py @@ -21,8 +21,7 @@ def run(cmd): returnCode = os.system(cmd) if (returnCode != 0): - # TODO(edgar): add as log.ODM_ERROR - sys.exit("\nquitting cause: \n\t" + cmd + "\nreturned with code " + + log.ODM_ERROR("quitting cause: \n\t" + cmd + "\nreturned with code " + str(returnCode) + ".\n")