Improve logging

This commit is contained in:
Frederik Ring 2024-01-29 16:20:50 +01:00
parent 7d489a95e3
commit 87ea8d0930

View File

@ -170,6 +170,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
} }
} }
if isDockerSwarm {
s.logger.Info( s.logger.Info(
fmt.Sprintf( 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.", "Stopping %d out of %d running container(s) and scaling down %d out of %d active service(s) as they were labeled %s.",
@ -180,6 +181,16 @@ func (s *script) stopContainersAndServices() (func() error, error) {
filterMatchLabel, 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 stoppedContainers []types.Container
var stopErrors []error var stopErrors []error
@ -309,6 +320,7 @@ func (s *script) stopContainersAndServices() (func() error, error) {
errors.Join(allErrors...), errors.Join(allErrors...),
) )
} }
if isDockerSwarm {
s.logger.Info( s.logger.Info(
fmt.Sprintf( fmt.Sprintf(
"Restarted %d container(s) and %d service(s).", "Restarted %d container(s) and %d service(s).",
@ -316,6 +328,15 @@ func (s *script) stopContainersAndServices() (func() error, error) {
len(scaledDownServices), len(scaledDownServices),
), ),
) )
} else {
s.logger.Info(
fmt.Sprintf(
"Restarted %d container(s).",
len(stoppedContainers),
),
)
}
return nil return nil
}, initialErr }, initialErr
} }