Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Jan 29, 2024
1 parent 7d489a9 commit 87ea8d0
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions cmd/backup/stop_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 87ea8d0

Please sign in to comment.