From 96c25799f5ab94136a1c8686afbee7d3d90a3008 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 22 May 2017 02:24:24 +0300 Subject: [PATCH] logger: use standard logging python module There is no need to keep our own implementation, as we have more versatile cross-platform standard module for it. For now just replacing Logger class guts with redirects to 'logging' module, and writing everything into single logging instance. --- dvc/logger.py | 67 +++++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/dvc/logger.py b/dvc/logger.py index 4d7b9ae20..3fc76a626 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -1,52 +1,35 @@ -class Logger(object): - DEFAULT_LEVEL = 2 +import logging - LEVEL = DEFAULT_LEVEL +class Logger(object): + DEFAULT_LEVEL = logging.INFO LEVEL_MAP = { - 'debug': 1, - 'info': 2, - 'warn': 3, - 'error': 4 + 'debug': logging.DEBUG, + 'info': logging.INFO, + 'warn': logging.WARNING, + 'error': logging.ERROR } + logging.basicConfig(stream=sys.stdout, format='%(message)s', level=DEFAULT_LEVEL) + + _logger = logging.getLogger('dvc') + @staticmethod def set_level(level): - Logger.LEVEL = Logger.LEVEL_MAP.get(level.lower(), 'debug') - - @staticmethod - def is_debug(): - return Logger.LEVEL <= 1 - - @staticmethod - def is_info(): - return Logger.LEVEL <= 2 - - @staticmethod - def is_warn(): - return Logger.LEVEL <= 3 - - @staticmethod - def is_error(): - return Logger.LEVEL <= 4 - - @staticmethod - def debug(msg): - if Logger.is_debug(): - print(u'Debug. {}'.format(msg)) - - @staticmethod - def info(msg): - if Logger.is_info(): - #print(u'Info. {}'.format(msg)) - print(msg) - - @staticmethod - def warn(msg): - if Logger.is_warn(): - print(u'Warning. {}'.format(msg)) + Logger._logger.setLevel(Logger.LEVEL_MAP.get(level.lower(), 'debug')) @staticmethod def error(msg): - if Logger.is_error(): - print(u'Error. {}'.format(msg)) + return Logger._logger.error(msg) + + @staticmethod + def warn(msg): + return Logger._logger.warn(msg) + + @staticmethod + def debug(msg): + return Logger._logger.debug(msg) + + @staticmethod + def info(msg): + return Logger._logger.info(msg)