mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #2513 from mheon/log_timestamps_newline
Ensure that each log line is newline-terminated
This commit is contained in:
@ -281,6 +281,7 @@ type logWriter struct {
|
|||||||
stderr io.Writer
|
stderr io.Writer
|
||||||
opts *LogOptions
|
opts *LogOptions
|
||||||
remain int64
|
remain int64
|
||||||
|
doAppend bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// errMaximumWrite is returned when all bytes have been written.
|
// errMaximumWrite is returned when all bytes have been written.
|
||||||
@ -309,9 +310,15 @@ func (w *logWriter) write(msg *logMessage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
line := msg.log
|
line := msg.log
|
||||||
if w.opts.Timestamps {
|
if w.opts.Timestamps && !w.doAppend {
|
||||||
prefix := append([]byte(msg.timestamp.Format(timeFormat)), delimiter[0])
|
prefix := append([]byte(msg.timestamp.Format(timeFormat)), delimiter[0])
|
||||||
line = append(prefix, line...)
|
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 the line is longer than the remaining bytes, cut it.
|
||||||
if int64(len(line)) > w.remain {
|
if int64(len(line)) > w.remain {
|
||||||
|
Reference in New Issue
Block a user