summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-10-23 15:59:48 -0200
committerKali Kaneko <kali@leap.se>2013-10-24 10:43:28 -0200
commit3a98bfed008fa1e02a7f5a63d5b9bc5e94ee630d (patch)
treeca5adcad5e1baa948c11b12f77d9573f9d36004e /src
parente149f7e3e6a5c4621edd252fd7f75c580c5e49b3 (diff)
use coloredlogs optionally
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/app.py18
1 files changed, 13 insertions, 5 deletions
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