Skip to content

Commit

Permalink
Merge pull request #19 from jpower432/bug/logging-stderr
Browse files Browse the repository at this point in the history
fix: updates logger and entrypoint script to log errors written to st…
  • Loading branch information
jpower432 authored Jul 11, 2023
2 parents aebe98e + f9c058b commit 7dfa741
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
9 changes: 2 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}\" \
Expand Down Expand Up @@ -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/.*: //')

Expand Down
2 changes: 1 addition & 1 deletion trestlebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from trestlebot.tasks.base_task import TaskBase, TaskException


logger = logging.getLogger(__name__)
logger = logging.getLogger("trestle")


class RepoException(Exception):
Expand Down
13 changes: 10 additions & 3 deletions trestlebot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -132,23 +132,30 @@ 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()


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]
Expand Down
4 changes: 2 additions & 2 deletions trestlebot/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7dfa741

Please sign in to comment.