From 4ff0df1b3581fdc28070f26f429b3dab7cba4637 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Wed, 4 Dec 2019 01:12:26 +0100 Subject: [PATCH] Clean up logging --- restic_compose_backup/cli.py | 14 +++++++------- restic_compose_backup/commands.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/restic_compose_backup/cli.py b/restic_compose_backup/cli.py index d180f8e..2b8e7fb 100644 --- a/restic_compose_backup/cli.py +++ b/restic_compose_backup/cli.py @@ -32,12 +32,9 @@ def main(): def status(config, containers): """Outputs the backup config for the compose setup""" - - logger.info("Backup config for compose project '%s'", containers.this_container.project_name) - logger.info("Current service: %s", containers.this_container.name) - # logger.info("Backup process: %s", containers.backup_process_container.name - # if containers.backup_process_container else 'Not Running') - logger.info("Backup running: %s", containers.backup_process_running) + logger.info("Status for compose project '%s'", containers.this_container.project_name) + logger.info("Backup currently running?: %s", containers.backup_process_running) + logger.info("%s Detected Config %s", "-" * 25, "-" * 25) backup_containers = containers.containers_for_backup() for container in backup_containers: @@ -51,10 +48,14 @@ def status(config, containers): instance = container.instance ping = instance.ping() logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) + if ping != 0: + logger.error("Database '%s' in service %s cannot be reached", instance.container_type, container.service_name) if len(backup_containers) == 0: logger.info("No containers in the project has 'restic-compose-backup.enabled' label") + logger.info("-" * 67) + def backup(config, containers): """Request a backup to start""" @@ -102,7 +103,6 @@ def start_backup_process(config, containers): return status(config, containers) - logger.info("start-backup-process") # Back up volumes try: diff --git a/restic_compose_backup/commands.py b/restic_compose_backup/commands.py index 3d97cd3..aa2d559 100644 --- a/restic_compose_backup/commands.py +++ b/restic_compose_backup/commands.py @@ -51,18 +51,18 @@ def ping_postgres(host, port, username, password) -> int: def run(cmd: List[str]) -> int: """Run a command with parameters""" - logger.info('cmd: %s', ' '.join(cmd)) + logger.debug('cmd: %s', ' '.join(cmd)) child = Popen(cmd, stdout=PIPE, stderr=PIPE) stdoutdata, stderrdata = child.communicate() if stdoutdata: - logger.info(stdoutdata.decode().strip()) - logger.info('-' * 28) + logger.debug(stdoutdata.decode().strip()) + logger.debug('-' * 28) if stderrdata: - logger.info('%s STDERR %s', '-' * 10, '-' * 10) - logger.info(stderrdata.decode().strip()) - logger.info('-' * 28) + logger.error('%s STDERR %s', '-' * 10, '-' * 10) + logger.error(stderrdata.decode().strip()) + logger.error('-' * 28) - logger.info("returncode %s", child.returncode) + logger.debug("returncode %s", child.returncode) return child.returncode