(dockerCLI command.Cli)
| 37 | } |
| 38 | |
| 39 | func newLogsCommand(dockerCLI command.Cli) *cobra.Command { |
| 40 | var opts logsOptions |
| 41 | |
| 42 | cmd := &cobra.Command{ |
| 43 | Use: "logs [OPTIONS] SERVICE|TASK", |
| 44 | Short: "Fetch the logs of a service or task", |
| 45 | Args: cli.ExactArgs(1), |
| 46 | RunE: func(cmd *cobra.Command, args []string) error { |
| 47 | opts.target = args[0] |
| 48 | return runLogs(cmd.Context(), dockerCLI, &opts) |
| 49 | }, |
| 50 | Annotations: map[string]string{"version": "1.29"}, |
| 51 | ValidArgsFunction: completeServiceNames(dockerCLI), |
| 52 | DisableFlagsInUseLine: true, |
| 53 | } |
| 54 | |
| 55 | flags := cmd.Flags() |
| 56 | // options specific to service logs |
| 57 | flags.BoolVar(&opts.noResolve, "no-resolve", false, "Do not map IDs to Names in output") |
| 58 | flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") |
| 59 | flags.BoolVar(&opts.raw, "raw", false, "Do not neatly format logs") |
| 60 | _ = flags.SetAnnotation("raw", "version", []string{"1.30"}) |
| 61 | flags.BoolVar(&opts.noTaskIDs, "no-task-ids", false, "Do not include task IDs in output") |
| 62 | // options identical to container logs |
| 63 | flags.BoolVarP(&opts.follow, "follow", "f", false, "Follow log output") |
| 64 | flags.StringVar(&opts.since, "since", "", `Show logs since timestamp (e.g. "2013-01-02T13:23:37Z") or relative (e.g. "42m" for 42 minutes)`) |
| 65 | flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps") |
| 66 | flags.BoolVar(&opts.details, "details", false, "Show extra details provided to logs") |
| 67 | _ = flags.SetAnnotation("details", "version", []string{"1.30"}) |
| 68 | flags.StringVarP(&opts.tail, "tail", "n", "all", "Number of lines to show from the end of the logs") |
| 69 | |
| 70 | return cmd |
| 71 | } |
| 72 | |
| 73 | func runLogs(ctx context.Context, dockerCli command.Cli, opts *logsOptions) error { //nolint:gocyclo |
| 74 | apiClient := dockerCli.Client() |
no test coverage detected
searching dependent graphs…