Merge pull request #32154 from dperny/refactor-logs

Refactor logs and support service logs with TTY
This commit is contained in:
Brian Goff 2017-04-07 18:06:50 -04:00 committed by GitHub
commit 5cf0c294d4
1 changed files with 22 additions and 0 deletions

View File

@ -73,6 +73,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error {
Timestamps: opts.timestamps, Timestamps: opts.timestamps,
Follow: opts.follow, Follow: opts.follow,
Tail: opts.tail, Tail: opts.tail,
Details: true,
} }
cli := dockerCli.Client() cli := dockerCli.Client()
@ -80,6 +81,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error {
var ( var (
maxLength = 1 maxLength = 1
responseBody io.ReadCloser responseBody io.ReadCloser
tty bool
) )
service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target) service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target)
@ -89,6 +91,14 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error {
return err return err
} }
task, _, err := cli.TaskInspectWithRaw(ctx, opts.target) 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 err != nil {
if client.IsErrTaskNotFound(err) { if client.IsErrTaskNotFound(err) {
// if the task ALSO isn't found, rewrite the error to be clear // 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) maxLength = getMaxLength(task.Slot)
responseBody, err = cli.TaskLogs(ctx, opts.target, options) responseBody, err = cli.TaskLogs(ctx, opts.target, options)
} else { } 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) responseBody, err = cli.ServiceLogs(ctx, opts.target, options)
if err != nil { if err != nil {
return err return err
@ -112,6 +129,11 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error {
} }
defer responseBody.Close() defer responseBody.Close()
if tty {
_, err = io.Copy(dockerCli.Out(), responseBody)
return err
}
taskFormatter := newTaskFormatter(cli, opts, maxLength) taskFormatter := newTaskFormatter(cli, opts, maxLength)
stdout := &logWriter{ctx: ctx, opts: opts, f: taskFormatter, w: dockerCli.Out()} stdout := &logWriter{ctx: ctx, opts: opts, f: taskFormatter, w: dockerCli.Out()}