Expose Null eventer and allow its use in the Podman CLI

We need this specifically for tests, but others may find it
useful if they don't explicitly need events and don't want the
performance implications of using them.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
Matthew Heon 2019-07-17 15:17:26 -04:00
parent fd73075cbe
commit cdd5639d56
5 changed files with 17 additions and 6 deletions

View file

@ -99,7 +99,7 @@ libpod to manage containers.
a slirp4netns network. If "" is used then the binary is looked up using the $PATH environment variable.
**events_logger**=""
Default method to use when logging events. Valid values are "journald" and "file".
Default method to use when logging events. Valid values are "file", "journald", and "null".
**detach_keys**=""
Keys sequence used for detaching a container

View file

@ -38,7 +38,7 @@ Path to where the cpu performance results should be written
**--events-logger**=**type**
Backend to use for storing events. Allowed values are **journald** and **file**.
Backend to use for storing events. Allowed values are **file**, **journald**, and **null**.
**--hooks-dir**=*path*

View file

@ -14,6 +14,8 @@ const (
LogFile EventerType = iota
// Journald indicates journald should be used to log events
Journald EventerType = iota
// Null is a no-op events logger. It does not read or write events.
Null EventerType = iota
)
// Event describes the attributes of a libpod event

View file

@ -16,11 +16,16 @@ var ErrNoJournaldLogging = errors.New("No support for journald logging")
// String returns a string representation of EventerType
func (et EventerType) String() string {
if et == LogFile {
switch et {
case LogFile:
return "file"
case Journald:
return "journald"
case Null:
return "null"
default:
return "invalid"
}
return "journald"
}
// IsValidEventer checks if the given string is a valid eventer type.
@ -30,6 +35,8 @@ func IsValidEventer(eventer string) bool {
return true
case Journald.String():
return true
case Null.String():
return true
default:
return false
}

View file

@ -18,8 +18,10 @@ func NewEventer(options EventerOptions) (eventer Eventer, err error) {
}
case strings.ToUpper(LogFile.String()):
eventer = EventLogFile{options}
case strings.ToUpper(Null.String()):
eventer = NewNullEventer()
default:
return eventer, errors.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
return nil, errors.Errorf("unknown event logger type: %s", strings.ToUpper(options.EventerType))
}
return eventer, nil
}