From 7ca54a397940c9e6696d07ad1cc1b3eb792b78b4 Mon Sep 17 00:00:00 2001 From: Drew Erny Date: Mon, 20 Mar 2017 10:07:04 -0700 Subject: [PATCH] refactor logs and support service logs /w tty Refactor container logs system to make communicating log messages internally much simpler. Move responsibility for marshalling log messages into the REST server. Support TTY logs. Pave the way for fixing the ambiguous bytestream format. Pave the way for fixing details. Signed-off-by: Drew Erny Upstream-commit: 938bf846e3ff6e4d8e94c2b146b9f95afababacd Component: cli --- components/cli/command/service/logs.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/cli/command/service/logs.go b/components/cli/command/service/logs.go index da2374f9dd..cfcb7ed105 100644 --- a/components/cli/command/service/logs.go +++ b/components/cli/command/service/logs.go @@ -73,6 +73,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { Timestamps: opts.timestamps, Follow: opts.follow, Tail: opts.tail, + Details: true, } cli := dockerCli.Client() @@ -80,6 +81,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { var ( maxLength = 1 responseBody io.ReadCloser + tty bool ) service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target) @@ -89,6 +91,14 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { return err } task, _, err := cli.TaskInspectWithRaw(ctx, opts.target) + tty = task.Spec.ContainerSpec.TTY + // TODO(dperny) hot fix until we get a nice details system squared away, + // ignores details (including task context) if we have a TTY log + if tty { + options.Details = false + } + + responseBody, err = cli.TaskLogs(ctx, opts.target, options) if err != nil { if client.IsErrTaskNotFound(err) { // if the task ALSO isn't found, rewrite the error to be clear @@ -100,6 +110,13 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { maxLength = getMaxLength(task.Slot) responseBody, err = cli.TaskLogs(ctx, opts.target, options) } else { + tty = service.Spec.TaskTemplate.ContainerSpec.TTY + // TODO(dperny) hot fix until we get a nice details system squared away, + // ignores details (including task context) if we have a TTY log + if tty { + options.Details = false + } + responseBody, err = cli.ServiceLogs(ctx, opts.target, options) if err != nil { return err @@ -112,6 +129,11 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { } defer responseBody.Close() + if tty { + _, err = io.Copy(dockerCli.Out(), responseBody) + return err + } + taskFormatter := newTaskFormatter(cli, opts, maxLength) stdout := &logWriter{ctx: ctx, opts: opts, f: taskFormatter, w: dockerCli.Out()}