Skip to content

Commit e5cd265

Browse files
gloursndeloof
authored andcommitted
improve watch configuration logging
Add action associated to each managed path Signed-off-by: Guillaume Lours <[email protected]>
1 parent d646d75 commit e5cd265

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pkg/compose/watch.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,27 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv
121121
dotGitIgnore,
122122
)
123123

124-
var paths []string
124+
var paths, pathLogs []string
125125
for _, trigger := range config.Watch {
126126
if checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) {
127127
logrus.Warnf("path '%s' also declared by a bind mount volume, this path won't be monitored!\n", trigger.Path)
128128
continue
129129
}
130130
paths = append(paths, trigger.Path)
131+
pathLogs = append(pathLogs, fmt.Sprintf("Action %s for path %q", trigger.Action, trigger.Path))
131132
}
132133

133134
watcher, err := watch.NewWatcher(paths, ignore)
134135
if err != nil {
135136
return err
136137
}
137138

138-
fmt.Fprintf(s.stdinfo(), "watching %s\n", paths)
139+
fmt.Fprintf(
140+
s.stdinfo(),
141+
"Watch configuration for service %q:%s\n",
142+
service.Name,
143+
strings.Join(append([]string{""}, pathLogs...), "\n - "),
144+
)
139145
err = watcher.Start()
140146
if err != nil {
141147
return err
@@ -420,7 +426,7 @@ func (s *composeService) handleWatchBatch(ctx context.Context, project *types.Pr
420426
if batch[i].Action == types.WatchActionRebuild {
421427
fmt.Fprintf(
422428
s.stdinfo(),
423-
"Rebuilding %s after changes were detected:%s\n",
429+
"Rebuilding service %q after changes were detected:%s\n",
424430
serviceName,
425431
strings.Join(append([]string{""}, batch[i].HostPath), "\n - "),
426432
)
@@ -477,7 +483,7 @@ func writeWatchSyncMessage(w io.Writer, serviceName string, pathMappings []sync.
477483
}
478484
fmt.Fprintf(
479485
w,
480-
"Syncing %s after changes were detected:%s\n",
486+
"Syncing %q after changes were detected:%s\n",
481487
serviceName,
482488
strings.Join(append([]string{""}, hostPathsToSync...), "\n - "),
483489
)
@@ -488,7 +494,7 @@ func writeWatchSyncMessage(w io.Writer, serviceName string, pathMappings []sync.
488494
}
489495
fmt.Fprintf(
490496
w,
491-
"Syncing %s after %d changes were detected\n",
497+
"Syncing service %q after %d changes were detected\n",
492498
serviceName,
493499
len(pathMappings),
494500
)

pkg/e2e/watch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func TestRebuildOnDotEnvWithExternalNetwork(t *testing.T) {
106106
out := r.String()
107107
errors := r.String()
108108
return strings.Contains(out,
109-
"watching"), fmt.Sprintf("'watching' not found in : \n%s\nStderr: \n%s\n", out,
109+
"Watch configuration"), fmt.Sprintf("'Watch configuration' not found in : \n%s\nStderr: \n%s\n", out,
110110
errors)
111111
}, 30*time.Second, 1*time.Second)
112112

0 commit comments

Comments
 (0)