From 87ea8d0930dd6ee36f24abc7e21971bb1804a3ad Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Mon, 29 Jan 2024 16:20:50 +0100 Subject: [PATCH] Improve logging --- cmd/backup/stop_restart.go | 55 ++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/cmd/backup/stop_restart.go b/cmd/backup/stop_restart.go index 0dba138..8c5d839 100644 --- a/cmd/backup/stop_restart.go +++ b/cmd/backup/stop_restart.go @@ -170,16 +170,27 @@ func (s *script) stopContainersAndServices() (func() error, error) { } } - s.logger.Info( - fmt.Sprintf( - "Stopping %d out of %d running container(s) and scaling down %d out of %d active service(s) as they were labeled %s.", - len(containersToStop), - len(allContainers), - len(servicesToScaleDown), - len(allServices), - filterMatchLabel, - ), - ) + if isDockerSwarm { + s.logger.Info( + fmt.Sprintf( + "Stopping %d out of %d running container(s) and scaling down %d out of %d active service(s) as they were labeled %s.", + len(containersToStop), + len(allContainers), + len(servicesToScaleDown), + len(allServices), + filterMatchLabel, + ), + ) + } else { + s.logger.Info( + fmt.Sprintf( + "Stopping %d out of %d running container(s) as they were labeled %s.", + len(containersToStop), + len(allContainers), + filterMatchLabel, + ), + ) + } var stoppedContainers []types.Container var stopErrors []error @@ -309,13 +320,23 @@ func (s *script) stopContainersAndServices() (func() error, error) { errors.Join(allErrors...), ) } - s.logger.Info( - fmt.Sprintf( - "Restarted %d container(s) and %d service(s).", - len(stoppedContainers), - len(scaledDownServices), - ), - ) + if isDockerSwarm { + s.logger.Info( + fmt.Sprintf( + "Restarted %d container(s) and %d service(s).", + len(stoppedContainers), + len(scaledDownServices), + ), + ) + } else { + s.logger.Info( + fmt.Sprintf( + "Restarted %d container(s).", + len(stoppedContainers), + ), + ) + } + return nil }, initialErr }