def update_reporting(self, global_options, is_quiet, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. removed_reporter = run_tracker.report.remove_reporter('capturing') buffered_out = self._consume_stringio(removed_reporter.settings.outfile) buffered_err = self._consume_stringio(removed_reporter.settings.errfile) log_level = Report.log_level_from_string(global_options.level or 'info') # Ideally, we'd use terminfo or somesuch to discover whether a # terminal truly supports color, but most that don't set TERM=dumb. color = global_options.colors and (os.getenv('TERM') != 'dumb') timing = global_options.time cache_stats = global_options.time # TODO: Separate flag for this? if is_quiet: console_reporter = QuietReporter(run_tracker, QuietReporter.Settings(log_level=log_level, color=color, timing=timing, cache_stats=cache_stats)) else: # Set up the new console reporter. stdout = sys.stdout.buffer stderr = sys.stderr.buffer settings = PlainTextReporter.Settings(log_level=log_level, outfile=stdout, errfile=stderr, color=color, indent=True, timing=timing, cache_stats=cache_stats, label_format=self.get_options().console_label_format, tool_output_format=self.get_options().console_tool_output_format) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_out, dest=ReporterDestination.OUT) console_reporter.emit(buffered_err, dest=ReporterDestination.ERR) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if global_options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(global_options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(global_options.logdir, '{}.log'.format(run_id)), 'wb') errfile = open(os.path.join(global_options.logdir, '{}.err.log'.format(run_id)), 'wb') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, errfile=errfile, color=False, indent=True, timing=True, cache_stats=True, label_format=self.get_options().console_label_format, tool_output_format=self.get_options().console_tool_output_format) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_out, dest=ReporterDestination.OUT) logfile_reporter.emit(buffered_err, dest=ReporterDestination.ERR) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter) invalidation_report = self._get_invalidation_report() if invalidation_report: run_id = run_tracker.run_info.get_info('id') outfile = os.path.join(self.get_options().reports_dir, run_id, 'invalidation-report.csv') invalidation_report.set_filename(outfile) return invalidation_report
def update_reporting(options, is_console_task, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. old_outfile = run_tracker.report.remove_reporter( 'capturing').settings.outfile old_outfile.flush() buffered_output = old_outfile.getvalue() old_outfile.close() log_level = Report.log_level_from_string(options.log_level or 'info') # Ideally, we'd use terminfo or somesuch to discover whether a # terminal truly supports color, but most that don't set TERM=dumb. color = (not options.no_color) and (os.getenv('TERM') != 'dumb') timing = options.time cache_stats = options.time # TODO: Separate flag for this? if options.quiet or is_console_task: console_reporter = QuietReporter( run_tracker, QuietReporter.Settings(log_level=log_level, color=color)) else: # Set up the new console reporter. settings = PlainTextReporter.Settings(log_level=log_level, outfile=sys.stdout, color=color, indent=True, timing=timing, cache_stats=cache_stats) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_output) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(options.logdir, '%s.log' % run_id), 'w') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, color=False, indent=True, timing=True, cache_stats=True) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_output) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter)
def update_reporting(self, global_options, is_quiet, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. removed_reporter = run_tracker.report.remove_reporter('capturing') buffered_out = self._consume_stringio(removed_reporter.settings.outfile) buffered_err = self._consume_stringio(removed_reporter.settings.errfile) log_level = Report.log_level_from_string(global_options.level or 'info') # Ideally, we'd use terminfo or somesuch to discover whether a # terminal truly supports color, but most that don't set TERM=dumb. color = global_options.colors and (os.getenv('TERM') != 'dumb') timing = global_options.time cache_stats = global_options.time # TODO: Separate flag for this? if is_quiet: console_reporter = QuietReporter(run_tracker, QuietReporter.Settings(log_level=log_level, color=color, timing=timing, cache_stats=cache_stats)) else: # Set up the new console reporter. stdout = sys.stdout.buffer if PY3 else sys.stdout stderr = sys.stderr.buffer if PY3 else sys.stderr settings = PlainTextReporter.Settings(log_level=log_level, outfile=stdout, errfile=stderr, color=color, indent=True, timing=timing, cache_stats=cache_stats, label_format=self.get_options().console_label_format, tool_output_format=self.get_options().console_tool_output_format) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_out, dest=ReporterDestination.OUT) console_reporter.emit(buffered_err, dest=ReporterDestination.ERR) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if global_options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(global_options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(global_options.logdir, '{}.log'.format(run_id)), 'wb') errfile = open(os.path.join(global_options.logdir, '{}.err.log'.format(run_id)), 'wb') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, errfile=errfile, color=False, indent=True, timing=True, cache_stats=True, label_format=self.get_options().console_label_format, tool_output_format=self.get_options().console_tool_output_format) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_out, dest=ReporterDestination.OUT) logfile_reporter.emit(buffered_err, dest=ReporterDestination.ERR) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter) invalidation_report = self._get_invalidation_report() if invalidation_report: run_id = run_tracker.run_info.get_info('id') outfile = os.path.join(self.get_options().reports_dir, run_id, 'invalidation-report.csv') invalidation_report.set_filename(outfile) return invalidation_report
def update_reporting(self, global_options, is_quiet_task, run_tracker, invalidation_report=None): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. old_outfile = run_tracker.report.remove_reporter('capturing').settings.outfile old_outfile.flush() buffered_output = old_outfile.getvalue() old_outfile.close() log_level = Report.log_level_from_string(global_options.level or 'info') # Ideally, we'd use terminfo or somesuch to discover whether a # terminal truly supports color, but most that don't set TERM=dumb. color = global_options.colors and (os.getenv('TERM') != 'dumb') timing = global_options.time cache_stats = global_options.time # TODO: Separate flag for this? if global_options.quiet or is_quiet_task: console_reporter = QuietReporter(run_tracker, QuietReporter.Settings(log_level=log_level, color=color)) else: # Set up the new console reporter. settings = PlainTextReporter.Settings(log_level=log_level, outfile=sys.stdout, color=color, indent=True, timing=timing, cache_stats=cache_stats) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_output) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if global_options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(global_options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(global_options.logdir, '{}.log'.format(run_id)), 'w') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, color=False, indent=True, timing=True, cache_stats=True) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_output) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter) if invalidation_report: run_id = run_tracker.run_info.get_info('id') outfile = os.path.join(self.get_options().reports_dir, run_id, 'invalidation-report.csv') invalidation_report.set_filename(outfile)
def update_reporting(options, is_console_task, run_tracker): """Updates reporting config once we've parsed cmd-line flags.""" # Get any output silently buffered in the old console reporter, and remove it. old_outfile = run_tracker.report.remove_reporter('capturing').settings.outfile old_outfile.flush() buffered_output = old_outfile.getvalue() old_outfile.close() log_level = Report.log_level_from_string(options.log_level or 'info') color = not options.no_color timing = options.time cache_stats = options.time # TODO: Separate flag for this? if options.quiet or is_console_task: console_reporter = QuietReporter(run_tracker, QuietReporter.Settings(log_level=log_level, color=color)) else: # Set up the new console reporter. settings = PlainTextReporter.Settings(log_level=log_level, outfile=sys.stdout, color=color, indent=True, timing=timing, cache_stats=cache_stats) console_reporter = PlainTextReporter(run_tracker, settings) console_reporter.emit(buffered_output) console_reporter.flush() run_tracker.report.add_reporter('console', console_reporter) if options.logdir: # Also write plaintext logs to a file. This is completely separate from the html reports. safe_mkdir(options.logdir) run_id = run_tracker.run_info.get_info('id') outfile = open(os.path.join(options.logdir, '%s.log' % run_id), 'w') settings = PlainTextReporter.Settings(log_level=log_level, outfile=outfile, color=False, indent=True, timing=True, cache_stats=True) logfile_reporter = PlainTextReporter(run_tracker, settings) logfile_reporter.emit(buffered_output) logfile_reporter.flush() run_tracker.report.add_reporter('logfile', logfile_reporter)