summaryrefslogtreecommitdiff
path: root/libpod/container_log_linux.go
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2019-05-22 11:46:26 -0400
committerPeter Hunt <pehunt@redhat.com>2019-05-28 11:14:08 -0400
commit88429242ddf82c03509ca66a687d9fb1534d2446 (patch)
tree5905a76af7396be8db361bd676349f243f5f8aae /libpod/container_log_linux.go
parent51bdf29f0493827ce3eb278a193d0a7402add896 (diff)
downloadpodman-88429242ddf82c03509ca66a687d9fb1534d2446.tar.gz
podman-88429242ddf82c03509ca66a687d9fb1534d2446.tar.bz2
podman-88429242ddf82c03509ca66a687d9fb1534d2446.zip
Add --follow to journald ctr logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/container_log_linux.go')
-rw-r--r--libpod/container_log_linux.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go
index 3b7945e0c..e549673a6 100644
--- a/libpod/container_log_linux.go
+++ b/libpod/container_log_linux.go
@@ -57,6 +57,20 @@ func (c *Container) readFromJournal(options *LogOptions, logChannel chan *LogLin
r.Rewind()
}
+ if options.Follow {
+ go func() {
+ follower := FollowBuffer{logChannel}
+ err := r.Follow(nil, follower)
+ if err != nil {
+ logrus.Debugf(err.Error())
+ }
+ r.Close()
+ options.WaitGroup.Done()
+ return
+ }()
+ return nil
+ }
+
go func() {
bytes := make([]byte, bufLen)
// /me complains about no do-while in go
@@ -84,8 +98,8 @@ func (c *Container) readFromJournal(options *LogOptions, logChannel chan *LogLin
func journalFormatter(entry *journal.JournalEntry) (string, error) {
usec := entry.RealtimeTimestamp
- timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))
- output := timestamp.Format(logTimeFormat) + " "
+ tsString := time.Unix(0, int64(usec)*int64(time.Microsecond)).Format(logTimeFormat)
+ output := fmt.Sprintf("%s ", tsString)
priority, ok := entry.Fields["PRIORITY"]
if !ok {
return "", errors.Errorf("no PRIORITY field present in journal entry")
@@ -113,3 +127,17 @@ func journalFormatter(entry *journal.JournalEntry) (string, error) {
output += strings.TrimSpace(msg)
return output, nil
}
+
+type FollowBuffer struct {
+ logChannel chan *LogLine
+}
+
+func (f FollowBuffer) Write(p []byte) (int, error) {
+ bytestr := string(p)
+ logLine, err := newLogLine(bytestr)
+ if err != nil {
+ return -1, err
+ }
+ f.logChannel <- logLine
+ return len(p), nil
+}