Skip to content

Commit

Permalink
Improved logging of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Oct 18, 2023
1 parent 23e4424 commit 826377f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/codemodder/codemodder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import difflib
import logging
import os
import sys
from pathlib import Path
Expand All @@ -10,7 +11,7 @@
from codemodder.file_context import FileContext

from codemodder import registry, __VERSION__
from codemodder.logging import configure_logger, logger, log_section
from codemodder.logging import configure_logger, logger, log_section, log_list
from codemodder.cli import parse_args
from codemodder.code_directory import file_line_patterns, match_files
from codemodder.context import CodemodExecutionContext, ChangeSet
Expand Down Expand Up @@ -106,9 +107,7 @@ def analyze_files(
)

if failures := execution_context.get_failures(codemod.id):
logger.info("failed:")
for name in failures:
logger.info(" - %s", name)
log_list(logging.INFO, "failed", failures)
if changes := execution_context.get_results(codemod.id):
logger.info("changed:")
for change in changes:
Expand Down Expand Up @@ -152,11 +151,9 @@ def run(original_args) -> int:
return 0

log_section("setup")
logger.info("running:")
for codemod in codemods_to_run:
logger.info(" - %s", codemod.id)
logger.info("including paths: %s", argv.path_include)
logger.info("excluding paths: %s", argv.path_exclude)
log_list(logging.INFO, "running", codemods_to_run, predicate=lambda c: c.id)
log_list(logging.INFO, "including paths", argv.path_include)
log_list(logging.INFO, "excluding paths", argv.path_exclude)

files_to_analyze = match_files(
context.directory, argv.path_exclude, argv.path_include
Expand All @@ -167,8 +164,7 @@ def run(original_args) -> int:

full_names = [str(path) for path in files_to_analyze]
logger.debug("matched files:")
for name in full_names:
logger.debug(" - %s", name)
log_list(logging.DEBUG, "matched files", full_names)

log_section("scanning")
# run codemods one at a time making sure to respect the given sequence
Expand Down
9 changes: 9 additions & 0 deletions src/codemodder/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def log_section(section_name: str):
logger.info("\n[%s]", section_name)


def log_list(level: int, header: str, items: list, predicate=None):
"""
Log a list of items.
"""
logger.log(level, "%s:", header)
for item in items:
logger.log(level, " - %s", predicate(item) if predicate else item)


def configure_logger(verbose: bool):
"""
Configure the logger based on the verbosity level.
Expand Down

0 comments on commit 826377f

Please sign in to comment.