diff options
author | Peter Hunt <pehunt@redhat.com> | 2019-05-18 22:17:37 -0400 |
---|---|---|
committer | Peter Hunt <pehunt@redhat.com> | 2019-05-28 11:10:57 -0400 |
commit | 02f971131a3bb71615d15a45df808edd0fa88266 (patch) | |
tree | 0802e2f2a3feb8c09458d1bebe003846e0f02aa2 /libpod/container_log.go | |
parent | 68ce353a23c8cd15077c70bc730470841ef37fb7 (diff) | |
download | podman-02f971131a3bb71615d15a45df808edd0fa88266.tar.gz podman-02f971131a3bb71615d15a45df808edd0fa88266.tar.bz2 podman-02f971131a3bb71615d15a45df808edd0fa88266.zip |
Implement podman logs with log-driver journald
Add a journald reader that translates the journald entry to a k8s-file formatted line, to be added as a log line
Note: --follow with journald hasn't been implemented. It's going to be a larger undertaking that can wait.
Signed-off-by: Peter Hunt <pehunt@redhat.com>
Diffstat (limited to 'libpod/container_log.go')
-rw-r--r-- | libpod/container_log.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/libpod/container_log.go b/libpod/container_log.go index f11db8014..9276b52f4 100644 --- a/libpod/container_log.go +++ b/libpod/container_log.go @@ -19,6 +19,16 @@ const ( // zeroes are not trimmed, taken from // https://github.com/golang/go/issues/19635 logTimeFormat = "2006-01-02T15:04:05.000000000Z07:00" + + // readLogTimeFormat is the format the log lines will be read in + readLogTimeFormat = time.RFC3339Nano + + // partialLogType signifies a log line that exceeded the buffer + // length and needed to spill into a new line + partialLogType = "P" + + // fullLogType signifies a log line is full + fullLogType = "F" ) // LogOptions is the options you can use for logs @@ -55,9 +65,16 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error { // TODO Skip sending logs until journald logs can be read // TODO make this not a magic string - if c.LogDriver() == "journald" { - return ErrNotImplemented + if c.LogDriver() == JournaldLogging { + if options.Follow { + return errors.Errorf("The follow option with journald logging is not currently supported") + } + return c.readFromJournal(options, logChannel) } + return c.readFromLogFile(options, logChannel) +} + +func (c *Container) readFromLogFile(options *LogOptions, logChannel chan *LogLine) error { t, tailLog, err := getLogFile(c.LogPath(), options) if err != nil { // If the log file does not exist, this is not fatal. @@ -196,7 +213,7 @@ func newLogLine(line string) (*LogLine, error) { if len(splitLine) < 4 { return nil, errors.Errorf("'%s' is not a valid container log line", line) } - logTime, err := time.Parse(time.RFC3339Nano, splitLine[0]) + logTime, err := time.Parse(readLogTimeFormat, splitLine[0]) if err != nil { return nil, errors.Wrapf(err, "unable to convert time %s from container log", splitLine[0]) } @@ -211,7 +228,7 @@ func newLogLine(line string) (*LogLine, error) { // Partial returns a bool if the log line is a partial log type func (l *LogLine) Partial() bool { - if l.ParseLogType == "P" { + if l.ParseLogType == partialLogType { return true } return false |