diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-10-26 20:33:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-26 20:33:26 +0000 |
commit | 12439543721f0c361a09866c8bba4220ef4e414c (patch) | |
tree | 47f045b1e12a5aa29e7f22a2889061b235606093 /libpod | |
parent | 22e5dc19b01e813ff73f4a5be2df9c4adf795fd2 (diff) | |
parent | c723e6b978090df43afb2462f647a4c2fde03c28 (diff) | |
download | podman-12439543721f0c361a09866c8bba4220ef4e414c.tar.gz podman-12439543721f0c361a09866c8bba4220ef4e414c.tar.bz2 podman-12439543721f0c361a09866c8bba4220ef4e414c.zip |
Merge pull request #12067 from hshiina/logs-journal-tail
Fix a few problems in 'podman logs --tail' with journald driver
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_log_linux.go | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go index 562169ce2..4029d0af7 100644 --- a/libpod/container_log_linux.go +++ b/libpod/container_log_linux.go @@ -121,7 +121,24 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption }() tailQueue := []*logs.LogLine{} // needed for options.Tail - doTail := options.Tail > 0 + doTail := options.Tail >= 0 + doTailFunc := func() { + // Flush *once* we hit the end of the journal. + startIndex := int64(len(tailQueue)) + outputLines := int64(0) + for startIndex > 0 && outputLines < options.Tail { + startIndex-- + for startIndex > 0 && tailQueue[startIndex].Partial() { + startIndex-- + } + outputLines++ + } + for i := startIndex; i < int64(len(tailQueue)); i++ { + logChannel <- tailQueue[i] + } + tailQueue = nil + doTail = false + } lastReadCursor := "" for { select { @@ -152,16 +169,7 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption // Hit the end of the journal (so far?). if cursor == lastReadCursor { if doTail { - // Flush *once* we hit the end of the journal. - startIndex := int64(len(tailQueue)-1) - options.Tail - if startIndex < 0 { - startIndex = 0 - } - for i := startIndex; i < int64(len(tailQueue)); i++ { - logChannel <- tailQueue[i] - } - tailQueue = nil - doTail = false + doTailFunc() } // Unless we follow, quit. if !options.Follow { @@ -194,6 +202,9 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption return } if status == events.Exited { + if doTail { + doTailFunc() + } return } continue |