Skip to content

Commit f791bc8

Browse files
author
Ulysses Souza
authored
Merge pull request docker#8984 from ndeloof/logs_restart
compose logs to notify printer about container lifecycle events
2 parents 7b84f2c + 0d75671 commit f791bc8

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

pkg/compose/logs.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,43 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
3434
}
3535

3636
eg, ctx := errgroup.WithContext(ctx)
37+
for _, c := range containers {
38+
c := c
39+
eg.Go(func() error {
40+
return s.logContainers(ctx, consumer, c, options)
41+
})
42+
}
43+
3744
if options.Follow {
3845
printer := newLogPrinter(consumer)
46+
eg.Go(func() error {
47+
for _, c := range containers {
48+
printer.HandleEvent(api.ContainerEvent{
49+
Type: api.ContainerEventAttach,
50+
Container: getContainerNameWithoutProject(c),
51+
Service: c.Labels[api.ServiceLabel],
52+
})
53+
}
54+
return nil
55+
})
56+
3957
eg.Go(func() error {
4058
return s.watchContainers(ctx, projectName, options.Services, printer.HandleEvent, containers, func(c types.Container) error {
59+
printer.HandleEvent(api.ContainerEvent{
60+
Type: api.ContainerEventAttach,
61+
Container: getContainerNameWithoutProject(c),
62+
Service: c.Labels[api.ServiceLabel],
63+
})
4164
return s.logContainers(ctx, consumer, c, options)
4265
})
4366
})
67+
4468
eg.Go(func() error {
4569
_, err := printer.Run(ctx, false, "", nil)
4670
return err
4771
})
4872
}
4973

50-
for _, c := range containers {
51-
c := c
52-
eg.Go(func() error {
53-
return s.logContainers(ctx, consumer, c, options)
54-
})
55-
}
5674
return eg.Wait()
5775
}
5876

0 commit comments

Comments
 (0)