Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If log driver is not 'json-file' use /attach API to get the log stream #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down