def _setup_console_logger(cls, session: AppSession, args, stderr): '''Set up the console logger. A handler and with a formatter is added to the root logger. ''' stream = new_encoded_stream(args, stderr) logger = logging.getLogger() session.console_log_handler = handler = logging.StreamHandler(stream) formatter = logging.Formatter('%(levelname)s %(message)s') log_filter = logging.Filter('wpull') handler.setFormatter(formatter) handler.setLevel(args.verbosity or logging.INFO) handler.addFilter(log_filter) logger.addHandler(handler)
def activate(self): super().activate() args = self.app_session.args if args.verbosity in (LOG_VERBOSE, LOG_DEBUG) and args.progress != 'none': stream = new_encoded_stream(args, self.app_session.stderr) bar_style = args.progress == 'bar' if not stream.isatty(): bar_style = False if bar_style: self._progress = BarProgress(stream=stream) else: self._progress = DotProgress(stream=stream) self._attach_event_listeners()