summaryrefslogtreecommitdiff
path: root/logging_ext.py
diff options
context:
space:
mode:
authorAurelien Campeas <aurelien.campeas@logilab.fr>2012-11-13 14:11:33 +0100
committerAurelien Campeas <aurelien.campeas@logilab.fr>2012-11-13 14:11:33 +0100
commit550ba6db7a6c7b72dde28b533838fb3ab4cd19f8 (patch)
tree53b11d9ab6d28d3d11b646fa63d7b6bccb4023bf /logging_ext.py
parent9fc4653fc67300e02b0d0a0ecd2fb4fe647780ab (diff)
downloadlogilab-common-550ba6db7a6c7b72dde28b533838fb3ab4cd19f8.tar.gz
[loggin ext] provide colored output under windows if colorama is available (closes #107436)
Diffstat (limited to 'logging_ext.py')
-rw-r--r--logging_ext.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/logging_ext.py b/logging_ext.py
index 1b7a1e6..e4d2490 100644
--- a/logging_ext.py
+++ b/logging_ext.py
@@ -132,9 +132,20 @@ def get_threshold(debug=False, logthreshold=None):
logthreshold))
return logthreshold
-def get_formatter(logformat=LOG_FORMAT, logdateformat=LOG_DATE_FORMAT):
+def _colorable_terminal():
isatty = hasattr(sys.__stdout__, 'isatty') and sys.__stdout__.isatty()
- if isatty and sys.platform != 'win32':
+ if not isatty:
+ return False
+ if os.name == 'nt':
+ try:
+ from colorama import init as init_win32_colors
+ except ImportError:
+ return False
+ init_win32_colors()
+ return True
+
+def get_formatter(logformat=LOG_FORMAT, logdateformat=LOG_DATE_FORMAT):
+ if _colorable_terminal():
fmt = ColorFormatter(logformat, logdateformat)
def col_fact(record):
if 'XXX' in record.message: