From 3a98bfed008fa1e02a7f5a63d5b9bc5e94ee630d Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 23 Oct 2013 15:59:48 -0200 Subject: use coloredlogs optionally --- src/leap/bitmask/app.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/leap') diff --git a/src/leap/bitmask/app.py b/src/leap/bitmask/app.py index 40a77075..3bb9c8c3 100644 --- a/src/leap/bitmask/app.py +++ b/src/leap/bitmask/app.py @@ -39,7 +39,6 @@ # M:::::::::::~NMMM7???7MMMM:::::::::::::::::::::::NMMMI??I7MMMM:::::::::::::M # M::::::::::::::7MMMMMMM+:::::::::::::::::::::::::::?MMMMMMMZ:::::::::::::::M # (thanks to: http://www.glassgiant.com/ascii/) - import logging import signal import sys @@ -105,9 +104,16 @@ def add_logger_handlers(debug=False, logfile=None): formatter = logging.Formatter(log_format) # Console handler - console = logging.StreamHandler() - console.setLevel(level) - console.setFormatter(formatter) + try: + import coloredlogs + console = coloredlogs.ColoredStreamHandler(level=level) + except ImportError: + console = logging.StreamHandler() + console.setLevel(level) + console.setFormatter(formatter) + using_coloredlog = False + else: + using_coloredlog = True silencer = log_silencer.SelectiveSilencerFilter() console.addFilter(silencer) @@ -131,6 +137,9 @@ def add_logger_handlers(debug=False, logfile=None): logger.addHandler(fileh) logger.debug('File handler plugged!') + if not using_coloredlog: + replace_stdout_stderr_with_logging(logger) + return logger @@ -185,7 +194,6 @@ def main(): BaseConfig.standalone = standalone logger = add_logger_handlers(debug, logfile) - replace_stdout_stderr_with_logging(logger) # And then we import all the other stuff from leap.bitmask.gui import locale_rc -- cgit v1.2.3