From e5cd265abbdd9d67d76558d3b8d2e7fec68b7573 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:57:42 +0100 Subject: [PATCH] improve watch configuration logging Add action associated to each managed path Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/watch.go | 16 +++++++++++----- pkg/e2e/watch_test.go | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/compose/watch.go b/pkg/compose/watch.go index 77696ea8b..a3961b793 100644 --- a/pkg/compose/watch.go +++ b/pkg/compose/watch.go @@ -121,13 +121,14 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv dotGitIgnore, ) - var paths []string + var paths, pathLogs []string for _, trigger := range config.Watch { if checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) { logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path) continue } paths = append(paths, trigger.Path) + pathLogs = append(pathLogs, fmt.Sprintf("Action %s for path %q", trigger.Action, trigger.Path)) } watcher, err := watch.NewWatcher(paths, ignore) @@ -135,7 +136,12 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv return err } - fmt.Fprintf(s.stdinfo(), "watching %s\n", paths) + fmt.Fprintf( + s.stdinfo(), + "Watch configuration for service %q:%s\n", + service.Name, + strings.Join(append([]string{""}, pathLogs...), "\n - "), + ) err = watcher.Start() if err != nil { return err @@ -420,7 +426,7 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr if batch[i].Action == types.WatchActionRebuild { fmt.Fprintf( s.stdinfo(), - "Rebuilding %s after changes were detected:%s\n", + "Rebuilding service %q after changes were detected:%s\n", serviceName, strings.Join(append([]string{""}, batch[i].HostPath), "\n - "), ) @@ -477,7 +483,7 @@ func writeWatchSyncMessage(w io.Writer, serviceName string, pathMappings []sync. } fmt.Fprintf( w, - "Syncing %s after changes were detected:%s\n", + "Syncing %q after changes were detected:%s\n", serviceName, strings.Join(append([]string{""}, hostPathsToSync...), "\n - "), ) @@ -488,7 +494,7 @@ func writeWatchSyncMessage(w io.Writer, serviceName string, pathMappings []sync. } fmt.Fprintf( w, - "Syncing %s after %d changes were detected\n", + "Syncing service %q after %d changes were detected\n", serviceName, len(pathMappings), ) diff --git a/pkg/e2e/watch_test.go b/pkg/e2e/watch_test.go index 2fabd1bac..2e03c081d 100644 --- a/pkg/e2e/watch_test.go +++ b/pkg/e2e/watch_test.go @@ -106,7 +106,7 @@ func TestRebuildOnDotEnvWithExternalNetwork(t *testing.T) { out := r.String() errors := r.String() return strings.Contains(out, - "watching"), fmt.Sprintf("'watching' not found in : \n%s\nStderr: \n%s\n", out, + "Watch configuration"), fmt.Sprintf("'Watch configuration' not found in : \n%s\nStderr: \n%s\n", out, errors) }, 30*time.Second, 1*time.Second)