From f901629a168f66632d41fcf8c28742452c80f409 Mon Sep 17 00:00:00 2001 From: Josselin Date: Wed, 8 May 2019 06:42:17 +0100 Subject: [PATCH] Use same json format output for file and stdout Improve --json helper Use logging.CRITICAL as an argument of logging.disable --- slither/__main__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/slither/__main__.py b/slither/__main__.py index 9d194a633..b37708fac 100644 --- a/slither/__main__.py +++ b/slither/__main__.py @@ -109,16 +109,17 @@ def wrap_json_stdout(success, error_message, results=None): def output_json(results, filename): + json_result = wrap_json_stdout(True, None, results) if filename is None: # Write json to console - print(json.dumps(wrap_json_stdout(True, None, results))) + print(json.dumps(json_result)) else: # Write json to file if os.path.isfile(filename): logger.info(yellow(f'{filename} exists already, the overwrite is prevented')) else: with open(filename, 'w', encoding='utf8') as f: - json.dump(results, f, indent=2) + json.dump(json_result, f, indent=2) # endregion ################################################################################### @@ -341,7 +342,7 @@ def parse_args(detector_classes, printer_classes): group_misc.add_argument('--json', - help='Export results as JSON', + help='Export the results as a JSON file ("--json -" to export to stdout)', action='store', default=defaults_flag_in_config['json']) @@ -515,7 +516,7 @@ def main_impl(all_detector_classes, all_printer_classes): # If we are outputting json to stdout, we'll want to disable any logging. stdout_json = args.json == "-" if stdout_json: - logging.disable() + logging.disable(logging.CRITICAL) printer_classes = choose_printers(args, all_printer_classes) detector_classes = choose_detectors(args, all_detector_classes)