From a330b0826232c14f7c4d894f862310f61e629c1c Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 7 Oct 2014 16:44:39 +0200 Subject: [PATCH] logging: Better colors Inspired by https://github.com/borntyping/python-colorlog INFO had no colors. You can run weboob/tools/log.py to test them. --- weboob/tools/log.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/weboob/tools/log.py b/weboob/tools/log.py index 861705a2..1577a416 100644 --- a/weboob/tools/log.py +++ b/weboob/tools/log.py @@ -17,10 +17,11 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . +from __future__ import print_function + +import sys from collections import defaultdict from logging import Filter, Formatter, getLogger as _getLogger -import sys - __all__ = ['getLogger', 'createColoredFormatter', 'settings'] @@ -29,9 +30,9 @@ RESET_SEQ = "\033[0m" COLOR_SEQ = "%s%%s" + RESET_SEQ COLORS = { - 'DEBUG': COLOR_SEQ % "\033[36m", - 'INFO': "%s", - 'WARNING': COLOR_SEQ % "\033[1;1m", + 'DEBUG': COLOR_SEQ % "\033[1;36m", + 'INFO': COLOR_SEQ % "\033[32m", + 'WARNING': COLOR_SEQ % "\033[1;33m", 'ERROR': COLOR_SEQ % "\033[1;31m", 'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"), } @@ -44,7 +45,7 @@ settings = defaultdict(lambda: None) def getLogger(name, parent=None): if parent: name = parent.name + '.' + name - logger = _getLogger(name) + logger = _getLogger(name) logger.settings = settings return logger @@ -77,3 +78,8 @@ def createColoredFormatter(stream, format): return ColoredFormatter(format) else: return Formatter(format) + + +if __name__ == '__main__': + for levelname, cs in COLORS.items(): + print(cs % levelname, end=' ')