summaryrefslogtreecommitdiff
path: root/libpod/logs/log.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-05-12 15:59:46 -0400
committerGitHub <noreply@github.com>2021-05-12 15:59:46 -0400
commitd6507fcfbce90b06a2b611a4cddadc3f64d51a4e (patch)
tree98d2001ec68f032e8132bc55f960ef71cc712ec3 /libpod/logs/log.go
parentd8dc56ba6758e590d14fca0c733246454837faf9 (diff)
parentd32863bbb4a2c2e8592766d84e16140fa71dcaa3 (diff)
downloadpodman-d6507fcfbce90b06a2b611a4cddadc3f64d51a4e.tar.gz
podman-d6507fcfbce90b06a2b611a4cddadc3f64d51a4e.tar.bz2
podman-d6507fcfbce90b06a2b611a4cddadc3f64d51a4e.zip
Merge pull request #10222 from vrothberg/image-tree
podman image tree: restore previous behavior
Diffstat (limited to 'libpod/logs/log.go')
-rw-r--r--libpod/logs/log.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/logs/log.go b/libpod/logs/log.go
index bba52408d..308053b47 100644
--- a/libpod/logs/log.go
+++ b/libpod/logs/log.go
@@ -206,6 +206,36 @@ func NewLogLine(line string) (*LogLine, error) {
return &l, nil
}
+// NewJournaldLogLine creates a LogLine from the specified line from journald.
+// Note that if withID is set, the first item of the message is considerred to
+// be the container ID and set as such.
+func NewJournaldLogLine(line string, withID bool) (*LogLine, error) {
+ splitLine := strings.Split(line, " ")
+ if len(splitLine) < 4 {
+ return nil, errors.Errorf("'%s' is not a valid container log line", line)
+ }
+ logTime, err := time.Parse(LogTimeFormat, splitLine[0])
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to convert time %s from container log", splitLine[0])
+ }
+ var msg, id string
+ if withID {
+ id = splitLine[3]
+ msg = strings.Join(splitLine[4:], " ")
+ } else {
+ msg = strings.Join(splitLine[3:], " ")
+ // NO ID
+ }
+ l := LogLine{
+ Time: logTime,
+ Device: splitLine[1],
+ ParseLogType: splitLine[2],
+ Msg: msg,
+ CID: id,
+ }
+ return &l, nil
+}
+
// Partial returns a bool if the log line is a partial log type
func (l *LogLine) Partial() bool {
return l.ParseLogType == PartialLogType