Ensure that each log line is newline-terminated

When writing logs with timestamps to the terminal, ensure that
each line is newline-terminated, so we don't end up with an
unreadable mess with timestamps interspersed with the actual
content being displayed.

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon
2019-03-03 21:13:49 -05:00
parent 5afae0b25b
commit e372837eb0

View File

@ -312,6 +312,10 @@ func (w *logWriter) write(msg *logMessage) error {
if w.opts.Timestamps {
prefix := append([]byte(msg.timestamp.Format(timeFormat)), delimiter[0])
line = append(prefix, line...)
// Ensure that lines always end in a newline
if line[len(line)-1] != '\n' {
line = append(line, '\n')
}
}
// If the line is longer than the remaining bytes, cut it.
if int64(len(line)) > w.remain {