From 3bf7fc225528d705b9655f5e6c3fa00b251bbc17 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Fri, 22 Dec 2023 22:22:02 +0100 Subject: [PATCH] feat: enhance logging - remove `*` from stack log entry - prefix log messages with arrow symbol for better readability --- dc-ops | 5 ++++- lib/helper.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dc-ops b/dc-ops index 965bda1..2651f96 100755 --- a/dc-ops +++ b/dc-ops @@ -47,7 +47,7 @@ for stack in cfg["stacks"]: # header stackdir = stack["dir"] - log.info(f"* processing {stackdir}") + log.info(f"processing: {stackdir}") # update repo and check for new commits if not update_git_repo(stackdir, args.ignore_git_status): @@ -55,6 +55,7 @@ for stack in cfg["stacks"]: # run pre-command if "pre" in stack: + log.info("-> executing pre-command") if not run_subprocess(stack["pre"], stackdir): continue @@ -62,6 +63,7 @@ for stack in cfg["stacks"]: # (or just for the directory if no compose-file defined) composefiles = stack.get("compose-files", ["docker-compose.yml"]) for composefile in composefiles: + log.info(f"-> bringing up {composefile}") if not run_subprocess( f"docker compose --file {composefile} up --detach {composeopts}", stackdir, @@ -70,5 +72,6 @@ for stack in cfg["stacks"]: # run post-command if "post" in stack: + log.info("-> executing post-command") if not run_subprocess(stack["post"], stackdir): continue diff --git a/lib/helper.py b/lib/helper.py index 9eae836..2bb56d5 100644 --- a/lib/helper.py +++ b/lib/helper.py @@ -16,9 +16,9 @@ def do_selfupdate(): log.error(str(e)) return if pull_res.old_commit: - log.info("selfupdate: successfully updated myself - exiting") + log.info("SelfUpdate: successfully updated myself - exiting") sys.exit(0) - log.info("selfupdate: no updates found for myself") + log.info("SelfUpdate: no updates found for myself") def run_subprocess(command: str, workdir: str) -> bool: @@ -49,11 +49,12 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool: Returns: bool: False if any step fails """ + # create repo instance if it exists try: repo = git.Repo(repo_path) except git.exc.NoSuchPathError: - log.error("directory not found") + log.error("-> directory not found") return False if not ignore_git_status: @@ -61,19 +62,19 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool: try: fetch_res = repo.remotes.origin.fetch()[0] except git.exc.GitCommandError as e: - log.error(str(e)) + log.error("-> " + str(e)) return False # check for new commits if not fetch_res.old_commit: - log.info("no changes - skipping") + log.info("-> no changes - skipping") return False # pull remote changes to local branch try: - log.info(repo.git.pull()) + log.info("-> " + repo.git.pull()) except git.exc.GitCommandError as e: - log.error(str(e)) + log.error("-> " + str(e)) return False return True