diff options
author | baude <bbaude@redhat.com> | 2019-03-27 13:50:54 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-04-24 16:00:04 -0500 |
commit | 7bf7c177ab3f67d5de1689842204c258fca083e4 (patch) | |
tree | 960fd1365913209fec61e3226b96a6f8bb1fd051 /libpod/events.go | |
parent | d75543fcd2ce87a9b87b8883400f355979004e91 (diff) | |
download | podman-7bf7c177ab3f67d5de1689842204c258fca083e4.tar.gz podman-7bf7c177ab3f67d5de1689842204c258fca083e4.tar.bz2 podman-7bf7c177ab3f67d5de1689842204c258fca083e4.zip |
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 <bbaude@redhat.com>
Diffstat (limited to 'libpod/events.go')
-rw-r--r-- | libpod/events.go | 69 |
1 files changed, 20 insertions, 49 deletions
diff --git a/libpod/events.go b/libpod/events.go index b6a277789..1b5c3bd99 100644 --- a/libpod/events.go +++ b/libpod/events.go @@ -1,14 +1,19 @@ package libpod import ( - "os" - "github.com/containers/libpod/libpod/events" - "github.com/hpcloud/tail" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) +// newEventer returns an eventer that can be used to read/write events +func (r *Runtime) newEventer() (events.Eventer, error) { + options := events.EventerOptions{ + EventerType: r.config.EventsLogger, + LogFilePath: r.config.EventsLogFilePath, + } + return events.NewEventer(options) +} + // newContainerEvent creates a new event based on a container func (c *Container) newContainerEvent(status events.Status) { e := events.NewEvent(status) @@ -16,8 +21,8 @@ func (c *Container) newContainerEvent(status events.Status) { e.Name = c.Name() e.Image = c.config.RootfsImageName e.Type = events.Container - if err := e.Write(c.runtime.config.EventsLogFilePath); err != nil { - logrus.Errorf("unable to write event to %s", c.runtime.config.EventsLogFilePath) + if err := c.runtime.eventer.Write(e); err != nil { + logrus.Errorf("unable to write pod event: %q", err) } } @@ -29,8 +34,8 @@ func (c *Container) newContainerExitedEvent(exitCode int32) { e.Image = c.config.RootfsImageName e.Type = events.Container e.ContainerExitCode = int(exitCode) - if err := e.Write(c.runtime.config.EventsLogFilePath); err != nil { - logrus.Errorf("unable to write event to %s", c.runtime.config.EventsLogFilePath) + if err := c.runtime.eventer.Write(e); err != nil { + logrus.Errorf("unable to write pod event: %q", err) } } @@ -40,8 +45,8 @@ func (p *Pod) newPodEvent(status events.Status) { e.ID = p.ID() e.Name = p.Name() e.Type = events.Pod - if err := e.Write(p.runtime.config.EventsLogFilePath); err != nil { - logrus.Errorf("unable to write event to %s", p.runtime.config.EventsLogFilePath) + if err := p.runtime.eventer.Write(e); err != nil { + logrus.Errorf("unable to write pod event: %q", err) } } @@ -50,51 +55,17 @@ func (v *Volume) newVolumeEvent(status events.Status) { e := events.NewEvent(status) e.Name = v.Name() e.Type = events.Volume - if err := e.Write(v.runtime.config.EventsLogFilePath); err != nil { - logrus.Errorf("unable to write event to %s", v.runtime.config.EventsLogFilePath) + if err := v.runtime.eventer.Write(e); err != nil { + logrus.Errorf("unable to write volume event: %q", err) } } // Events is a wrapper function for everyone to begin tailing the events log // with options -func (r *Runtime) Events(fromStart, stream bool, options []events.EventFilter, eventChannel chan *events.Event) error { - if !r.valid { - return ErrRuntimeStopped - } - - t, err := r.getTail(fromStart, stream) +func (r *Runtime) Events(options events.ReadOptions) error { + eventer, err := r.newEventer() if err != nil { return err } - for line := range t.Lines { - event, err := events.NewEventFromString(line.Text) - if err != nil { - return err - } - switch event.Type { - case events.Image, events.Volume, events.Pod, events.Container: - // no-op - default: - return errors.Errorf("event type %s is not valid in %s", event.Type.String(), r.config.EventsLogFilePath) - } - include := true - for _, filter := range options { - include = include && filter(event) - } - if include { - eventChannel <- event - } - } - close(eventChannel) - return nil -} - -func (r *Runtime) getTail(fromStart, stream bool) (*tail.Tail, error) { - reopen := true - seek := tail.SeekInfo{Offset: 0, Whence: os.SEEK_END} - if fromStart || !stream { - seek.Whence = 0 - reopen = false - } - return tail.TailFile(r.config.EventsLogFilePath, tail.Config{ReOpen: reopen, Follow: stream, Location: &seek, Logger: tail.DiscardingLogger}) + return eventer.Read(options) } |