mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 07:18:27 +01:00
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:
+24
-4
@@ -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'))
|
||||
|
||||
@@ -84,3 +84,4 @@ simplegeneric==0.8.1
|
||||
six==1.10.0
|
||||
traitlets==4.3.2
|
||||
wcwidth==0.1.7
|
||||
colorama
|
||||
|
||||
Reference in New Issue
Block a user