summaryrefslogtreecommitdiff
path: root/libpod/container_log_linux.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-08-04 15:24:29 -0400
committerNalin Dahyabhai <nalin@redhat.com>2021-08-23 17:59:42 -0400
commit6b06e9b77c8191096eeb82ac54c59b894f87da8c (patch)
treefc41fbf93803440eedd99d34d1a60c00110ce5c2 /libpod/container_log_linux.go
parentd1137664fe799bb9ca84ed9e4e0d01db6df77bad (diff)
downloadpodman-6b06e9b77c8191096eeb82ac54c59b894f87da8c.tar.gz
podman-6b06e9b77c8191096eeb82ac54c59b894f87da8c.tar.bz2
podman-6b06e9b77c8191096eeb82ac54c59b894f87da8c.zip
Switch eventlogger to journald by default
[NO TESTS NEEDED] Since we are just testing the default. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/container_log_linux.go')
-rw-r--r--libpod/container_log_linux.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/libpod/container_log_linux.go b/libpod/container_log_linux.go
index 4eb600bfe..748f80fa5 100644
--- a/libpod/container_log_linux.go
+++ b/libpod/container_log_linux.go
@@ -12,6 +12,7 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/libpod/logs"
+ "github.com/coreos/go-systemd/v22/journal"
"github.com/coreos/go-systemd/v22/sdjournal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -29,6 +30,17 @@ func init() {
logDrivers = append(logDrivers, define.JournaldLogging)
}
+// initializeJournal will write an empty string to the journal
+// when a journal is created. This solves a problem when people
+// attempt to read logs from a container that has never had stdout/stderr
+func (c *Container) initializeJournal(ctx context.Context) error {
+ m := make(map[string]string)
+ m["SYSLOG_IDENTIFIER"] = "podman"
+ m["PODMAN_ID"] = c.ID()
+ m["CONTAINER_ID_FULL"] = c.ID()
+ return journal.Send("", journal.PriInfo, m)
+}
+
func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error {
journal, err := sdjournal.NewJournal()
if err != nil {
@@ -63,12 +75,12 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
}
// API requires Next() immediately after SeekHead().
if _, err := journal.Next(); err != nil {
- return errors.Wrap(err, "initial journal cursor")
+ return errors.Wrap(err, "next journal")
}
// API requires a next|prev before getting a cursor.
if _, err := journal.Previous(); err != nil {
- return errors.Wrap(err, "initial journal cursor")
+ return errors.Wrap(err, "previous journal")
}
// Note that the initial cursor may not yet be ready, so we'll do an