Add logging module

pull/266/head
Dakota Benjamin 2016-03-03 11:31:25 -05:00
rodzic fea6bcccbe
commit b807b07920
2 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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")