From 7bf7c177ab3f67d5de1689842204c258fca083e4 Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 27 Mar 2019 13:50:54 -0500 Subject: journald event logging add the ability for podman to read and write events to journald instead of just a logfile. This can be controlled in libpod.conf with the `events_logger` attribute of `journald` or `file`. The default will be set to `journald`. Signed-off-by: baude --- libpod/image/image.go | 6 ++++-- libpod/image/image_test.go | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'libpod/image') diff --git a/libpod/image/image.go b/libpod/image/image.go index 757d034a2..27773edcf 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -66,6 +66,8 @@ type Runtime struct { store storage.Store SignaturePolicyPath string EventsLogFilePath string + EventsLogger string + Eventer events.Eventer } // InfoImage keep information of Image along with all associated layers @@ -1203,7 +1205,7 @@ func (ir *Runtime) newImageEvent(status events.Status, name string) { e := events.NewEvent(status) e.Type = events.Image e.Name = name - if err := e.Write(ir.EventsLogFilePath); err != nil { + if err := ir.Eventer.Write(e); err != nil { logrus.Infof("unable to write event to %s", ir.EventsLogFilePath) } } @@ -1216,7 +1218,7 @@ func (i *Image) newImageEvent(status events.Status) { if len(i.Names()) > 0 { e.Name = i.Names()[0] } - if err := e.Write(i.imageruntime.EventsLogFilePath); err != nil { + if err := i.imageruntime.Eventer.Write(e); err != nil { logrus.Infof("unable to write event to %s", i.imageruntime.EventsLogFilePath) } } diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index 075ba119d..dfe817c90 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -3,6 +3,7 @@ package image import ( "context" "fmt" + "github.com/containers/libpod/libpod/events" "io" "io/ioutil" "os" @@ -87,6 +88,7 @@ func TestImage_NewFromLocal(t *testing.T) { // Need images to be present for this test ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) + ir.Eventer = events.NewNullEventer() bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, false, nil) assert.NoError(t, err) bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, false, nil) @@ -127,6 +129,7 @@ func TestImage_New(t *testing.T) { } ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) + ir.Eventer = events.NewNullEventer() // Build the list of pull names names = append(names, bbNames...) names = append(names, fedoraNames...) @@ -164,6 +167,7 @@ func TestImage_MatchRepoTag(t *testing.T) { } ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) + ir.Eventer = events.NewNullEventer() newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, false, nil) assert.NoError(t, err) err = newImage.TagImage("foo:latest") -- cgit v1.2.3-54-g00ecf