mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
compose logs to notify printer about container lifecycle events
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
7b84f2c2a5
commit
0d7567131a
@ -34,25 +34,43 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
|
|||||||
}
|
}
|
||||||
|
|
||||||
eg, ctx := errgroup.WithContext(ctx)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
if options.Follow {
|
|
||||||
printer := newLogPrinter(consumer)
|
|
||||||
eg.Go(func() error {
|
|
||||||
return s.watchContainers(ctx, projectName, options.Services, printer.HandleEvent, containers, func(c types.Container) error {
|
|
||||||
return s.logContainers(ctx, consumer, c, options)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
eg.Go(func() error {
|
|
||||||
_, err := printer.Run(ctx, false, "", nil)
|
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
c := c
|
c := c
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
return s.logContainers(ctx, consumer, c, options)
|
return s.logContainers(ctx, consumer, c, options)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Follow {
|
||||||
|
printer := newLogPrinter(consumer)
|
||||||
|
eg.Go(func() error {
|
||||||
|
for _, c := range containers {
|
||||||
|
printer.HandleEvent(api.ContainerEvent{
|
||||||
|
Type: api.ContainerEventAttach,
|
||||||
|
Container: getContainerNameWithoutProject(c),
|
||||||
|
Service: c.Labels[api.ServiceLabel],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
eg.Go(func() error {
|
||||||
|
return s.watchContainers(ctx, projectName, options.Services, printer.HandleEvent, containers, func(c types.Container) error {
|
||||||
|
printer.HandleEvent(api.ContainerEvent{
|
||||||
|
Type: api.ContainerEventAttach,
|
||||||
|
Container: getContainerNameWithoutProject(c),
|
||||||
|
Service: c.Labels[api.ServiceLabel],
|
||||||
|
})
|
||||||
|
return s.logContainers(ctx, consumer, c, options)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
eg.Go(func() error {
|
||||||
|
_, err := printer.Run(ctx, false, "", nil)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return eg.Wait()
|
return eg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user