diff options
Diffstat (limited to 'logging_ext.py')
-rw-r--r-- | logging_ext.py | 15 |
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: |