# Own modules
from . import __version__ as GLOBAL_VERSION
+from fb_logging.colored import ColoredFormatter
+
from fb_tools.common import pp
from fb_tools.app import BaseApplication
def init_logging(self):
"""Initialize the logger object."""
- super(CrTplApplication, self).init_logging()
+ # super(CrTplApplication, self).init_logging()
+
+ log_level = logging.INFO
+ if self.verbose:
+ log_level = logging.DEBUG
+ elif self.quiet:
+ log_level = logging.WARNING
+
+ root_logger = logging.getLogger()
+ root_logger.setLevel(log_level)
+
+ # create formatter
+ format_str = ''
+ if self.verbose:
+ format_str = '[%(asctime)s]: '
+ format_str += self.appname + ': '
+ if self.verbose:
+ if self.verbose > 1:
+ format_str += '%(name)s(%(lineno)d) %(funcName)s() '
+ else:
+ format_str += '%(name)s '
+ format_str += '%(levelname)s - %(message)s'
+ formatter = None
+ if self.terminal_has_colors:
+ formatter = ColoredFormatter(format_str)
+ else:
+ formatter = logging.Formatter(format_str)
+
+ # ---------------------
+ class StdoutFilter(logging.Filter):
+ def filter(self, record):
+ return record.levelno in (logging.DEBUG, logging.INFO)
+
+ if not self.quiet:
+
+ # create log handler for console stdout
+ lh_stdout = logging.StreamHandler(sys.stdout)
+ lh_stdout.setLevel(log_level)
+ lh_stdout.addFilter(StdoutFilter())
+ lh_stdout.setFormatter(formatter)
+
+ root_logger.addHandler(lh_stdout)
+
+ # create log handler for console stderr
+ lh_stderr = logging.StreamHandler(sys.stderr)
+ lh_stderr.setLevel(logging.WARNING)
+ lh_stderr.setFormatter(formatter)
+
+ root_logger.addHandler(lh_stderr)
if self.verbose < 4:
paramiko_logger = logging.getLogger('paramiko.transport')