diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-03-04 08:38:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 08:38:18 -0800 |
commit | 34bf58c5dbb898ef9f813e79b13735eecc933369 (patch) | |
tree | eb5e7bb9d5d0536d6d4f3d0cda85c913998eb46a /pkg | |
parent | 54eecb02f050d743c7a00f5d8e2e8ffbdc26d568 (diff) | |
parent | ff609a5ade6991ef1d8f892a7bce44a039fbe174 (diff) | |
download | podman-34bf58c5dbb898ef9f813e79b13735eecc933369.tar.gz podman-34bf58c5dbb898ef9f813e79b13735eecc933369.tar.bz2 podman-34bf58c5dbb898ef9f813e79b13735eecc933369.zip |
Merge pull request #2513 from mheon/log_timestamps_newline
Ensure that each log line is newline-terminated
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/logs/logs.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index b104c592b..bbd5509b1 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -277,10 +277,11 @@ func readLog(reader *bufio.Reader, opts *LogOptions) []string { // logWriter controls the writing into the stream based on the log options. type logWriter struct { - stdout io.Writer - stderr io.Writer - opts *LogOptions - remain int64 + stdout io.Writer + stderr io.Writer + opts *LogOptions + remain int64 + doAppend bool } // errMaximumWrite is returned when all bytes have been written. @@ -309,9 +310,15 @@ func (w *logWriter) write(msg *logMessage) error { return nil } line := msg.log - if w.opts.Timestamps { + if w.opts.Timestamps && !w.doAppend { prefix := append([]byte(msg.timestamp.Format(timeFormat)), delimiter[0]) line = append(prefix, line...) + if len(line) > 0 && line[len(line)-1] != '\n' { + w.doAppend = true + } + } + if w.doAppend && len(line) > 0 && line[len(line)-1] == '\n' { + w.doAppend = false } // If the line is longer than the remaining bytes, cut it. if int64(len(line)) > w.remain { |