Issues #23 and #236: Use docker logs to get all logs from the container, including those before supervisor start

We've been using docker attach, which only gives us the logs since we attach. This change allows getting the
full logs from the beginning.
We also use the timestamps that come with the logs from docker, as they will be more precise and are more relevant now
that we're getting previous logs from history.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-03-06 17:18:03 -03:00 committed by Pablo Carranza Vélez
parent b64ed9568c
commit b6206f9012

View File

@ -97,12 +97,17 @@ do ->
if !attached[app.containerId]
dockerPromise.then (docker) ->
docker.getContainer(app.containerId)
.attachAsync({ stream: true, stdout: true, stderr: true, tty: true })
.logsAsync({ follow: true, stdout: true, stderr: true, timestamps: true })
.then (stream) ->
attached[app.containerId] = true
stream.pipe(es.split())
.on('data', publish)
.on 'error', ->
.on 'data', (logLine) ->
space = logLine.indexOf(' ')
if space > 0
msg = { t: logLine.substr(0, space), m: logLine.substr(space + 1) }
publish(msg)
.on 'error', (err) ->
console.error('Error on container logs', err, err.stack)
attached[app.containerId] = false
.on 'end', ->
attached[app.containerId] = false