dvc: logger: use colorama to colorize output

Colors help readability, especially in verbose mode.
Current color map:

	Debug:   Blue
	Info:    White
	Warning: Yellow
	Error:   Red
This commit is contained in:
Ruslan Kuprieiev
2017-05-22 14:44:31 +03:00
parent 57a30764b7
commit e02437ed97
3 changed files with 26 additions and 4 deletions
+24 -4
View File
@@ -1,5 +1,8 @@
import sys
import logging
import colorama
class Logger(object):
DEFAULT_LEVEL = logging.INFO
@@ -10,6 +13,12 @@ class Logger(object):
'error': logging.ERROR
}
COLOR_MAP = {
'debug': colorama.Fore.BLUE,
'warn': colorama.Fore.YELLOW,
'error': colorama.Fore.RED
}
logging.basicConfig(stream=sys.stdout, format='%(message)s', level=DEFAULT_LEVEL)
_logger = logging.getLogger('dvc')
@@ -26,18 +35,29 @@ class Logger(object):
def be_verbose():
Logger._logger.setLevel(logging.DEBUG)
@staticmethod
def colorize(msg, typ):
header = ''
footer = ''
if sys.stdout.isatty():
header = Logger.COLOR_MAP.get(typ.lower(), '')
footer = colorama.Style.RESET_ALL
return u'{}{}{}'.format(header, msg, footer)
@staticmethod
def error(msg):
return Logger._logger.error(msg)
return Logger._logger.error(Logger.colorize(msg, 'error'))
@staticmethod
def warn(msg):
return Logger._logger.warn(msg)
return Logger._logger.warn(Logger.colorize(msg, 'warn'))
@staticmethod
def debug(msg):
return Logger._logger.debug(msg)
return Logger._logger.debug(Logger.colorize(msg, 'debug'))
@staticmethod
def info(msg):
return Logger._logger.info(msg)
return Logger._logger.info(Logger.colorize(msg, 'info'))
+1
View File
@@ -84,3 +84,4 @@ simplegeneric==0.8.1
six==1.10.0
traitlets==4.3.2
wcwidth==0.1.7
colorama
+1
View File
@@ -90,6 +90,7 @@ install_requires = [
'six==1.10.0',
'traitlets==4.3.2',
'wcwidth==0.1.7',
'colorama',
]
if platform.system() == 'Darwin':