summaryrefslogtreecommitdiff
path: root/logging_ext.py
diff options
context:
space:
mode:
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>2007-08-30 22:08:17 +0200
committerNicolas Chauvat <nicolas.chauvat@logilab.fr>2007-08-30 22:08:17 +0200
commit74050982985a5ac74b35f5a0ae0955c050ffdf85 (patch)
tree37e818ec913e00a7065acdedacfef0615e430d1b /logging_ext.py
parenteaa5bf093756d6872a79f9b7c05e90dc7bafa551 (diff)
downloadlogilab-common-74050982985a5ac74b35f5a0ae0955c050ffdf85.tar.gz
helper function set_color_formatter()
Diffstat (limited to 'logging_ext.py')
-rw-r--r--logging_ext.py16
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)