aboutsummaryrefslogtreecommitdiff
path: root/pkg/logs
diff options
context:
space:
mode:
authorMatthew Heon <mheon@redhat.com>2019-03-03 23:06:32 -0500
committerMatthew Heon <mheon@redhat.com>2019-03-03 23:06:32 -0500
commit429f2e63a0e2a3b1e084371ebed280a6288b7617 (patch)
treeb905b9b60d2c466ee06ce49774f15d4f7a3a7b02 /pkg/logs
parente372837eb0dcafdf2fb5c3029ba340bbd9117fc3 (diff)
downloadpodman-429f2e63a0e2a3b1e084371ebed280a6288b7617.tar.gz
podman-429f2e63a0e2a3b1e084371ebed280a6288b7617.tar.bz2
podman-429f2e63a0e2a3b1e084371ebed280a6288b7617.zip
When logging with timestamps, append only until newline
When we log time timestamps, don't print a new timestamp for each input - instead, print one at the start of every line, and then wait until we hit a newline to print a new timestamp. This still doesn't exactly mirror the Docker behavior (they don't print until they receive an entire line, while we print any time the logs file is appended to - so you can see partial lines being typed in our system). Also, timestamps are recorded as the start of a line being typed, as opposed to when the enter key is pressed (on Docker). (Worth noting that, while characters are printed as they are typed, logs does respect the backspace key - so you'll also see them disappear as the person typing realizes they've made a mistake and retypes their command). This is the closest we can get to Docker without major surgery on the Kubernetes log-printing library, so I'm content to call this an adequate solution. Signed-off-by: Matthew Heon <mheon@redhat.com>
Diffstat (limited to 'pkg/logs')
-rw-r--r--pkg/logs/logs.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go
index fe4474f8b..1d920d691 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,14 +310,16 @@ 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...)
- // Ensure that lines always end in a newline
if line[len(line)-1] != '\n' {
- line = append(line, '\n')
+ w.doAppend = true
}
}
+ if w.doAppend && 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 {
line = line[:w.remain]