From f9c058b37b1afad1cdb70561a8106632e78ffafb Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Tue, 11 Jul 2023 12:14:02 -0400 Subject: [PATCH] fix: updates logger and entrypoint script to log errors written to stderr Signed-off-by: Jennifer Power --- entrypoint.sh | 9 ++------- trestlebot/bot.py | 2 +- trestlebot/cli.py | 13 ++++++++++--- trestlebot/log.py | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2b845bcf..ad5700e7 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -19,11 +19,6 @@ else git config --global --add safe.directory "$INPUT_REPOSITORY" fi -exec 3>&1 - -trap exec 3>&- EXIT - - # Initialize the command variable command="python3.8 -m trestlebot \ --markdown-path=\"${INPUT_MARKDOWN_PATH}\" \ @@ -52,8 +47,8 @@ if [[ ${INPUT_CHECK_ONLY} == true ]]; then command+=" --check-only" fi -output=$(eval "$command" 2>&1 > >(tee /dev/fd/3)) - +exec 3>&1 +output=$(eval "$command" > >(tee /dev/fd/3) 2>&1) commit=$(echo "$output" | grep "Commit Hash:" | sed 's/.*: //') diff --git a/trestlebot/bot.py b/trestlebot/bot.py index a8143bd6..002db4f3 100644 --- a/trestlebot/bot.py +++ b/trestlebot/bot.py @@ -26,7 +26,7 @@ from trestlebot.tasks.base_task import TaskBase, TaskException -logger = logging.getLogger(__name__) +logger = logging.getLogger("trestle") class RepoException(Exception): diff --git a/trestlebot/cli.py b/trestlebot/cli.py index ac7a8d18..086e91e0 100644 --- a/trestlebot/cli.py +++ b/trestlebot/cli.py @@ -29,7 +29,7 @@ from trestlebot.tasks.regenerate_task import RegenerateTask -logger = logging.getLogger("trestlebot") +logger = logging.getLogger("trestle") def _parse_cli_arguments() -> argparse.Namespace: @@ -132,6 +132,12 @@ def _parse_cli_arguments() -> argparse.Namespace: default="ssp-index.json", help="Path to ssp index file", ) + parser.add_argument( + "--verbose", + required=False, + action="store_true", + help="Run in verbose mode", + ) return parser.parse_args() @@ -139,16 +145,17 @@ def handle_exception( exception: Exception, msg: str = "Exception occurred during execution" ) -> int: """Log the exception and return the exit code""" - logger.error(msg + f": {exception}") + logger.error(msg + f": {exception}", exc_info=True) return 1 def run() -> None: """Trestle Bot entry point function.""" - log.set_global_logging_levels() args = _parse_cli_arguments() + log.set_log_level_from_args(args=args) + pre_tasks: List[TaskBase] = [] authored_list: List[str] = [model.value for model in types.AuthoredType] diff --git a/trestlebot/log.py b/trestlebot/log.py index e7279acf..80207bdb 100644 --- a/trestlebot/log.py +++ b/trestlebot/log.py @@ -23,8 +23,8 @@ # Singleton logger instance # All other CLI sub module will inherit settings of this logger as long as -# sub-module instantiates a logger with a prefix 'trestlebot' or __name__ -_logger = logging.getLogger("trestlebot") +# sub-module instantiates a logger with a prefix 'trestle' or __name__ +_logger = logging.getLogger("trestle") class SpecificLevelFilter(logging.Filter):