From eb93d956ca0c9fc8a04224faa5ed3f9b8f9d8afb Mon Sep 17 00:00:00 2001 From: Tomas Nozicka Date: Wed, 13 Dec 2017 18:33:14 +0100 Subject: [PATCH] journald logs: drain 1 more time at container exit --- daemon/logger/journald/read.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/daemon/logger/journald/read.go b/daemon/logger/journald/read.go index bc009f61cf4cd..cf758c97ff705 100644 --- a/daemon/logger/journald/read.go +++ b/daemon/logger/journald/read.go @@ -252,6 +252,13 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re errstr := C.GoString(cerrstr) fmtstr := "error %q while attempting to follow journal for container %q" logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"]) + } else { + // In the event that we were told to stop (logWatcher.WatchClose() below), it's possible + // there's more data in the journal for this container that was written just as the container + // exited. Try to drain the journal one more time to pick up any last-minute journal entries. + // Note, this isn't fool-proof and there's no guarantee that we'll get all the trailing + // entries, but this is better than nothing, as it does yield entries more often than not. + s.drainJournal(logWatcher, config, j, cursor) } // Clean up. C.close(pfd[0])