summaryrefslogtreecommitdiff
path: root/libpod/container_log.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_log.go')
-rw-r--r--libpod/container_log.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go
index bfa303e84..39c395fe6 100644
--- a/libpod/container_log.go
+++ b/libpod/container_log.go
@@ -2,6 +2,7 @@ package libpod
import (
"os"
+ "time"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/logs"
@@ -19,7 +20,7 @@ func (r *Runtime) Log(containers []*Container, options *logs.LogOptions, logChan
return nil
}
-// ReadLog reads a containers log based on the input options and returns loglines over a channel
+// ReadLog reads a containers log based on the input options and returns loglines over a channel.
func (c *Container) ReadLog(options *logs.LogOptions, logChannel chan *logs.LogLine) error {
// TODO Skip sending logs until journald logs can be read
// TODO make this not a magic string
@@ -61,7 +62,7 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l
partial += nll.Msg
continue
} else if !nll.Partial() && len(partial) > 1 {
- nll.Msg = partial
+ nll.Msg = partial + nll.Msg
partial = ""
}
nll.CID = c.ID()
@@ -72,5 +73,27 @@ func (c *Container) readFromLogFile(options *logs.LogOptions, logChannel chan *l
}
options.WaitGroup.Done()
}()
+ // Check if container is still running or paused
+ go func() {
+ if options.Follow {
+ for {
+ state, err := c.State()
+ if err != nil && errors.Cause(err) != define.ErrNoSuchCtr {
+ logrus.Error(err)
+ break
+ } else if err != nil {
+ break
+ }
+ if state != define.ContainerStateRunning && state != define.ContainerStatePaused {
+ err := t.Stop()
+ if err != nil {
+ logrus.Error(err)
+ }
+ break
+ }
+ time.Sleep(1 * time.Second)
+ }
+ }
+ }()
return nil
}