diff options
author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2007-08-30 22:08:17 +0200 |
---|---|---|
committer | Nicolas Chauvat <nicolas.chauvat@logilab.fr> | 2007-08-30 22:08:17 +0200 |
commit | 74050982985a5ac74b35f5a0ae0955c050ffdf85 (patch) | |
tree | 37e818ec913e00a7065acdedacfef0615e430d1b /logging_ext.py | |
parent | eaa5bf093756d6872a79f9b7c05e90dc7bafa551 (diff) | |
download | logilab-common-74050982985a5ac74b35f5a0ae0955c050ffdf85.tar.gz |
helper function set_color_formatter()
Diffstat (limited to 'logging_ext.py')
-rw-r--r-- | logging_ext.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/logging_ext.py b/logging_ext.py index 08a1a97..dee73a6 100644 --- a/logging_ext.py +++ b/logging_ext.py @@ -1,4 +1,4 @@ -# -*- encoding: iso-8859-1 -*- +# -*- coding: iso-8859-1 -*- # Copyright (c) 2006 LOGILAB S.A. (Paris, FRANCE). # http://www.logilab.fr/ -- mailto:contact@logilab.fr # @@ -24,6 +24,10 @@ import logging from logilab.common.textutils import colorize_ansi +def xxx_cyan(record): + if 'XXX' in record.message: + return 'cyan' + class ColorFormatter(logging.Formatter): """ A color Formatter for the logging standard module. @@ -58,3 +62,13 @@ class ColorFormatter(logging.Formatter): if color: return colorize_ansi(msg, color) return msg + +def set_color_formatter(logger=None): + if logger is None: + logger = logging.getLogger() + if not logger.handlers: + logging.basicConfig() + format_msg = logger.handlers[0].formatter._fmt + fmt = ColorFormatter(format_msg) + fmt.colorfilters.append(xxx_cyan) + logger.handlers[0].setFormatter(fmt) |