From cddcabc6d6d8c231272e6e237e81c0513ab1f8f8 Mon Sep 17 00:00:00 2001 From: Christian Beedgen Date: Sun, 26 Apr 2015 01:38:28 -0700 Subject: [PATCH] If log driver is not 'json-file' use /attach API to get the log stream --- router/pump.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/router/pump.go b/router/pump.go index 2e6270a2..d30be392 100644 --- a/router/pump.go +++ b/router/pump.go @@ -63,6 +63,10 @@ func ignoreContainer(container *docker.Container) bool { return false } +func hasJsonFile(container *docker.Container) bool { + return container.HostConfig.LogConfig.Type == "json-file" +} + type update struct { *docker.APIEvents pump *containerPump @@ -143,15 +147,31 @@ func (p *LogsPump) pumpLogs(event *docker.APIEvents, backlog bool) { p.update(event) debug("pump:", id, "started") go func() { - err := p.client.Logs(docker.LogsOptions{ - Container: id, - OutputStream: outwr, - ErrorStream: errwr, - Stdout: true, - Stderr: true, - Follow: true, - Tail: tail, - }) + var err error + // Log drivers other than 'json-file' will not support the /logs API + if hasJsonFile(container) { + debug("pump:", id, "using /logs") + err = p.client.Logs(docker.LogsOptions{ + Container: id, + OutputStream: outwr, + ErrorStream: errwr, + Stdout: true, + Stderr: true, + Follow: true, + Tail: tail, + }) + } else { + debug("pump:", id, "using /attach") + err = p.client.AttachToContainer(docker.AttachToContainerOptions{ + Container: id, + OutputStream: outwr, + ErrorStream: errwr, + Stdout: true, + Stderr: true, + Logs: false, + Stream: true, + }) + } if err != nil { debug("pump:", id, "stopped:", err) }