diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-06-22 18:10:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-22 18:10:06 +0200 |
commit | 11dd5f51b6c2a644dc4793b8f18ec541593a30ee (patch) | |
tree | dc313bb205da5e7c582a299439384f55e17efe61 /libpod | |
parent | 78b205c8c9d2c06e563174b38039b0fcb2f6933e (diff) | |
parent | 173d08637411629a271ab162d917f6ccee438dae (diff) | |
download | podman-11dd5f51b6c2a644dc4793b8f18ec541593a30ee.tar.gz podman-11dd5f51b6c2a644dc4793b8f18ec541593a30ee.tar.bz2 podman-11dd5f51b6c2a644dc4793b8f18ec541593a30ee.zip |
Merge pull request #6702 from jgallucci32/follow-logs-poll
Stop following logs using timers
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_log.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go index 071882bc2..67380397a 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -1,10 +1,13 @@ package libpod import ( + "fmt" "os" + "time" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/libpod/logs" + "github.com/hpcloud/tail/watch" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -81,5 +84,31 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l } options.WaitGroup.Done() }() + // Check if container is still running or paused + if options.Follow { + go func() { + for { + state, err := c.State() + time.Sleep(watch.POLL_DURATION) + if err != nil { + tailError := t.StopAtEOF() + if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" { + logrus.Error(tailError) + } + if errors.Cause(err) != define.ErrNoSuchCtr { + logrus.Error(err) + } + break + } + if state != define.ContainerStateRunning && state != define.ContainerStatePaused { + tailError := t.StopAtEOF() + if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" { + logrus.Error(tailError) + } + break + } + } + }() + } return nil } |