summaryrefslogtreecommitdiff
path: root/libpod/container_log.go
diff options
context:
space:
mode:
authorjgallucci32 <john.gallucci.iv@gmail.com>2020-06-20 09:45:18 -0700
committerMatthew Heon <mheon@redhat.com>2020-06-24 14:35:04 -0400
commit07f535d8b7595388e9e45203f2d7a77cbf78b977 (patch)
tree8dea4e082eac1c098b47e63130e3541fbd2d6e30 /libpod/container_log.go
parentdbce3468e0adaecb6fc8cb6eaa159e5a30eb749c (diff)
downloadpodman-07f535d8b7595388e9e45203f2d7a77cbf78b977.tar.gz
podman-07f535d8b7595388e9e45203f2d7a77cbf78b977.tar.bz2
podman-07f535d8b7595388e9e45203f2d7a77cbf78b977.zip
Stop following logs using timers
This incorporates code from PR #6591 and #6614 but does not use event channels to detect container state and rather uses timers with a defined wait duration before calling t.StopAtEOF() to ensure the last log entry is output before a container exits. The polling interval is set to 250 milliseconds based on polling interval defined in hpcloud/tail here: https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117 Co-authored-by: Qi Wang <qiwan@redhat.com> Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
Diffstat (limited to 'libpod/container_log.go')
-rw-r--r--libpod/container_log.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go
index 071882bc2..9a2f8aa2f 100644
--- a/libpod/container_log.go
+++ b/libpod/container_log.go
@@ -1,7 +1,9 @@
package libpod
import (
+ "fmt"
"os"
+ "time"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/logs"
@@ -81,5 +83,33 @@ 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()
+ if err != nil {
+ time.Sleep(250 * time.Millisecond)
+ 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 {
+ time.Sleep(250 * time.Millisecond)
+ tailError := t.StopAtEOF()
+ if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" {
+ logrus.Error(tailError)
+ }
+ break
+ }
+ time.Sleep(250 * time.Millisecond)
+ }
+ }()
+ }
return nil
}