Clean up logging

This commit is contained in:
Einar Forselv 2019-12-04 01:12:26 +01:00
parent c78d208e66
commit 4ff0df1b35
2 changed files with 14 additions and 14 deletions

View File

@ -32,12 +32,9 @@ def main():
def status(config, containers): def status(config, containers):
"""Outputs the backup config for the compose setup""" """Outputs the backup config for the compose setup"""
logger.info("Status for compose project '%s'", containers.this_container.project_name)
logger.info("Backup config for compose project '%s'", containers.this_container.project_name) logger.info("Backup currently running?: %s", containers.backup_process_running)
logger.info("Current service: %s", containers.this_container.name) logger.info("%s Detected Config %s", "-" * 25, "-" * 25)
# 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)
backup_containers = containers.containers_for_backup() backup_containers = containers.containers_for_backup()
for container in backup_containers: for container in backup_containers:
@ -51,10 +48,14 @@ def status(config, containers):
instance = container.instance instance = container.instance
ping = instance.ping() ping = instance.ping()
logger.info(' - %s (is_ready=%s)', instance.container_type, ping == 0) 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: if len(backup_containers) == 0:
logger.info("No containers in the project has 'restic-compose-backup.enabled' label") logger.info("No containers in the project has 'restic-compose-backup.enabled' label")
logger.info("-" * 67)
def backup(config, containers): def backup(config, containers):
"""Request a backup to start""" """Request a backup to start"""
@ -102,7 +103,6 @@ def start_backup_process(config, containers):
return return
status(config, containers) status(config, containers)
logger.info("start-backup-process")
# Back up volumes # Back up volumes
try: try:

View File

@ -51,18 +51,18 @@ def ping_postgres(host, port, username, password) -> int:
def run(cmd: List[str]) -> int: def run(cmd: List[str]) -> int:
"""Run a command with parameters""" """Run a command with parameters"""
logger.info('cmd: %s', ' '.join(cmd)) logger.debug('cmd: %s', ' '.join(cmd))
child = Popen(cmd, stdout=PIPE, stderr=PIPE) child = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdoutdata, stderrdata = child.communicate() stdoutdata, stderrdata = child.communicate()
if stdoutdata: if stdoutdata:
logger.info(stdoutdata.decode().strip()) logger.debug(stdoutdata.decode().strip())
logger.info('-' * 28) logger.debug('-' * 28)
if stderrdata: if stderrdata:
logger.info('%s STDERR %s', '-' * 10, '-' * 10) logger.error('%s STDERR %s', '-' * 10, '-' * 10)
logger.info(stderrdata.decode().strip()) logger.error(stderrdata.decode().strip())
logger.info('-' * 28) logger.error('-' * 28)
logger.info("returncode %s", child.returncode) logger.debug("returncode %s", child.returncode)
return child.returncode return child.returncode