Logs returns logs for a site's given container. See docker.LogsOptions for more information about valid tailLines values.
(service string, follow bool, timestamps bool, tailLines string)
| 2669 | // Logs returns logs for a site's given container. |
| 2670 | // See docker.LogsOptions for more information about valid tailLines values. |
| 2671 | func (app *DdevApp) Logs(service string, follow bool, timestamps bool, tailLines string) error { |
| 2672 | ctx, apiClient, err := dockerutil.GetDockerClient() |
| 2673 | if err != nil { |
| 2674 | return err |
| 2675 | } |
| 2676 | |
| 2677 | var c *container.Summary |
| 2678 | // Let people access ddev-router and ddev-ssh-agent logs as well. |
| 2679 | if service == "ddev-router" || service == "ddev-ssh-agent" { |
| 2680 | c, err = dockerutil.FindContainerByLabels(map[string]string{ |
| 2681 | "com.docker.compose.service": service, |
| 2682 | "com.docker.compose.oneoff": "False", |
| 2683 | }) |
| 2684 | } else { |
| 2685 | c, err = app.FindContainerByType(service) |
| 2686 | } |
| 2687 | if err != nil { |
| 2688 | return err |
| 2689 | } |
| 2690 | if c == nil { |
| 2691 | util.Warning("No running service container %s was found", service) |
| 2692 | return nil |
| 2693 | } |
| 2694 | |
| 2695 | logOpts := client.ContainerLogsOptions{ |
| 2696 | ShowStdout: true, |
| 2697 | ShowStderr: true, |
| 2698 | Follow: follow, |
| 2699 | Timestamps: timestamps, |
| 2700 | } |
| 2701 | |
| 2702 | if tailLines != "" { |
| 2703 | logOpts.Tail = tailLines |
| 2704 | } |
| 2705 | |
| 2706 | rc, err := apiClient.ContainerLogs(ctx, c.ID, logOpts) |
| 2707 | if err != nil { |
| 2708 | return err |
| 2709 | } |
| 2710 | defer rc.Close() |
| 2711 | |
| 2712 | // Copy logs to user output |
| 2713 | _, err = stdcopy.StdCopy(output.UserOut.Out, output.UserOut.Out, rc) |
| 2714 | if err != nil { |
| 2715 | return fmt.Errorf("failed to copy container logs: %v", err) |
| 2716 | } |
| 2717 | |
| 2718 | return nil |
| 2719 | } |
| 2720 | |
| 2721 | // CaptureLogs returns logs for a site's given container. |
| 2722 | // See docker.LogsOptions for more information about valid tailLines values. |
no test coverage detected