diff --git a/src/codemodder/cli.py b/src/codemodder/cli.py index 7f80e4fa..271dabe9 100644 --- a/src/codemodder/cli.py +++ b/src/codemodder/cli.py @@ -2,7 +2,7 @@ import sys from codemodder import __VERSION__ -from codemodder.logging import logger +from codemodder.logging import OutputFormat, logger class ArgumentParser(argparse.ArgumentParser): @@ -134,6 +134,13 @@ def parse_args(argv, codemod_registry): action=argparse.BooleanOptionalAction, help="print more to stdout", ) + parser.add_argument( + "--log-format", + type=OutputFormat, + default=OutputFormat.HUMAN, + choices=[str(x).split(".")[-1].lower() for x in list(OutputFormat)], + help="the format for the log output", + ) parser.add_argument( "--path-exclude", action=CsvListAction, diff --git a/src/codemodder/logging.py b/src/codemodder/logging.py index 5251d224..986cf4dd 100644 --- a/src/codemodder/logging.py +++ b/src/codemodder/logging.py @@ -1,3 +1,4 @@ +from enum import Enum import logging import sys @@ -5,6 +6,15 @@ logger = logging.getLogger("codemodder") +class OutputFormat(Enum): + """ + Enum for the output format of the logger. + """ + + HUMAN = "human" + JSON = "json" + + def configure_logger(verbose: bool): """ Configure the logger based on the verbosity level.