logger: Only send logs produced after attaching

The previous approach had the bad side effect of resending tons of logs
in the case of a supervisor restart.

The approach can be improved by storing the last timestamp per container
and re-attaching at the correct point.

Change-type: minor
Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
This commit is contained in:
Petros Angelatos 2018-07-13 18:05:11 -07:00
parent 0d812c272c
commit 6766c23bd9
No known key found for this signature in database
GPG Key ID: 7DE8B46CDBCB42A1

View File

@ -187,7 +187,7 @@ module.exports = class Logger
if stdoutOrStderr not in [ 'stdout', 'stderr' ]
throw new Error("Invalid log selection #{stdoutOrStderr}")
if !@attached[stdoutOrStderr][containerId]
logsOpts = { follow: true, stdout: stdoutOrStderr == 'stdout', stderr: stdoutOrStderr == 'stderr', timestamps: true }
logsOpts = { follow: true, stdout: stdoutOrStderr == 'stdout', stderr: stdoutOrStderr == 'stderr', timestamps: true, since: Math.floor(Date.now() / 1000) }
docker.getContainer(containerId)
.logs(logsOpts)
.then (stream) =>