( ctx context.Context, projectName string, consumer api.LogConsumer, options api.LogOptions, )
| 32 | ) |
| 33 | |
| 34 | func (s *composeService) Logs( |
| 35 | ctx context.Context, |
| 36 | projectName string, |
| 37 | consumer api.LogConsumer, |
| 38 | options api.LogOptions, |
| 39 | ) error { |
| 40 | var containers Containers |
| 41 | var err error |
| 42 | |
| 43 | if options.Index > 0 { |
| 44 | ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, options.Services[0], options.Index) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | containers = append(containers, ctr) |
| 49 | } else { |
| 50 | containers, err = s.getContainers(ctx, projectName, oneOffExclude, true, options.Services...) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if options.Project != nil && len(options.Services) == 0 { |
| 57 | // we run with an explicit compose.yaml, so only consider services defined in this file |
| 58 | options.Services = options.Project.ServiceNames() |
| 59 | containers = containers.filter(isService(options.Services...)) |
| 60 | } |
| 61 | |
| 62 | eg, ctx := errgroup.WithContext(ctx) |
| 63 | for _, ctr := range containers { |
| 64 | eg.Go(func() error { |
| 65 | err := s.logContainer(ctx, consumer, ctr, options) |
| 66 | if errdefs.IsNotImplemented(err) { |
| 67 | logrus.Warnf("Can't retrieve logs for %q: %s", getCanonicalContainerName(ctr), err.Error()) |
| 68 | return nil |
| 69 | } |
| 70 | return err |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | if options.Follow { |
| 75 | printer := newLogPrinter(consumer) |
| 76 | |
| 77 | monitor := newMonitor(s.apiClient(), projectName) |
| 78 | if len(options.Services) > 0 { |
| 79 | monitor.withServices(options.Services) |
| 80 | } else if options.Project != nil { |
| 81 | monitor.withServices(options.Project.ServiceNames()) |
| 82 | } |
| 83 | monitor.withListener(printer.HandleEvent) |
| 84 | monitor.withListener(func(event api.ContainerEvent) { |
| 85 | if event.Type == api.ContainerEventStarted { |
| 86 | eg.Go(func() error { |
| 87 | res, err := s.apiClient().ContainerInspect(ctx, event.ID, client.ContainerInspectOptions{}) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 |
nothing calls this directly
no test coverage detected