From 26b7b775c2ebe7bf5e69d940d483cd21c726fec5 Mon Sep 17 00:00:00 2001 From: Daniel D'Avella Date: Tue, 10 Oct 2023 16:50:11 -0400 Subject: [PATCH] Separate log section headers --- src/codemodder/codemodder.py | 10 +++++----- src/codemodder/logging.py | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/codemodder/codemodder.py b/src/codemodder/codemodder.py index c907c96e..f2b50f31 100644 --- a/src/codemodder/codemodder.py +++ b/src/codemodder/codemodder.py @@ -10,7 +10,7 @@ from codemodder.file_context import FileContext from codemodder import registry, __VERSION__ -from codemodder.logging import configure_logger, logger +from codemodder.logging import configure_logger, logger, log_section from codemodder.cli import parse_args from codemodder.code_directory import file_line_patterns, match_files from codemodder.context import CodemodExecutionContext, ChangeSet @@ -132,7 +132,7 @@ def run(original_args) -> int: configure_logger(argv.verbose) - logger.info("[startup]") + log_section("startup") logger.info("codemodder: python/%s", __VERSION__) context = CodemodExecutionContext( @@ -151,7 +151,7 @@ def run(original_args) -> int: logger.error("no codemods to run") return 0 - logger.info("[setup]") + log_section("setup") logger.info("running:") for codemod in codemods_to_run: logger.info(" - %s", codemod.id) @@ -170,7 +170,7 @@ def run(original_args) -> int: for name in full_names: logger.debug(" - %s", name) - logger.info("[scanning]") + log_section("scanning") # run codemods one at a time making sure to respect the given sequence for codemod in codemods_to_run: logger.info("running codemod %s", codemod.id) @@ -190,7 +190,7 @@ def run(original_args) -> int: elapsed_ms = int(elapsed.total_seconds() * 1000) report_default(elapsed_ms, argv, original_args, results) - logger.info("[report]") + log_section("report") logger.info("scanned: %s files", len(files_to_analyze)) all_failures = context.get_failed_files() logger.info( diff --git a/src/codemodder/logging.py b/src/codemodder/logging.py index a8e9feaa..a3c9fc94 100644 --- a/src/codemodder/logging.py +++ b/src/codemodder/logging.py @@ -14,6 +14,13 @@ class OutputFormat(Enum): JSON = "json" +def log_section(section_name: str): + """ + Log a section header. + """ + logger.info("\n[%s]", section_name) + + def configure_logger(verbose: bool): """ Configure the logger based on the verbosity level.