From d2794a06ce3aaa154e89df1fe8d5e8cd4c723019 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Mon, 8 Oct 2018 16:32:20 +0800 Subject: [PATCH] bugfix: jsonfile log should be compatible with moby source in jsonfile log should be marshaled to stream. Signed-off-by: Wei Fu --- daemon/logger/jsonfile/encode.go | 16 ++++++++-------- daemon/logger/jsonfile/utils_test.go | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/daemon/logger/jsonfile/encode.go b/daemon/logger/jsonfile/encode.go index 5b35ebad8..f1525a020 100644 --- a/daemon/logger/jsonfile/encode.go +++ b/daemon/logger/jsonfile/encode.go @@ -12,9 +12,9 @@ import ( ) type jsonLog struct { - Source string `json:"source,omitempty"` - Line string `json:"line,omitempty"` - Timestamp time.Time `json:"timestamp,omitempty"` + Stream string `json:"stream,omitempty"` + Log string `json:"log,omitempty"` + Timestamp time.Time `json:"time"` } func newUnmarshal(r io.Reader) func() (*logger.LogMessage, error) { @@ -27,8 +27,8 @@ func newUnmarshal(r io.Reader) func() (*logger.LogMessage, error) { } return &logger.LogMessage{ - Source: jl.Source, - Line: []byte(jl.Line), + Source: jl.Stream, + Line: []byte(jl.Log), Timestamp: jl.Timestamp, }, nil } @@ -43,7 +43,7 @@ func marshal(msg *logger.LogMessage) ([]byte, error) { buf.WriteString("{") if len(msg.Source) != 0 { first = false - buf.WriteString(`"source":`) + buf.WriteString(`"stream":`) bytesIntoJSONString(&buf, []byte(msg.Source)) } @@ -52,7 +52,7 @@ func marshal(msg *logger.LogMessage) ([]byte, error) { buf.WriteString(`,`) } first = false - buf.WriteString(`"line":`) + buf.WriteString(`"log":`) bytesIntoJSONString(&buf, msg.Line) } @@ -60,7 +60,7 @@ func marshal(msg *logger.LogMessage) ([]byte, error) { buf.WriteString(`,`) } - buf.WriteString(`"timestamp":`) + buf.WriteString(`"time":`) buf.WriteString(msg.Timestamp.UTC().Format(`"` + utils.TimeLayout + `"`)) buf.WriteString(`}`) diff --git a/daemon/logger/jsonfile/utils_test.go b/daemon/logger/jsonfile/utils_test.go index 4754e6d15..5747cc28b 100644 --- a/daemon/logger/jsonfile/utils_test.go +++ b/daemon/logger/jsonfile/utils_test.go @@ -84,16 +84,16 @@ func TestSeekOffsetByTailLines(t *testing.T) { } const ( - logContentPart1 = `{"source":"stdout","line":"#1","timestamp":"2018-05-09T10:00:01Z"} -{"source":"stdout","line":"#2","timestamp":"2018-05-09T10:00:02Z"} -{"source":"stdout","line":"#3","timestamp":"2018-05-09T10:00:03Z"} + logContentPart1 = `{"stream":"stdout","log":"#1","time":"2018-05-09T10:00:01Z"} +{"stream":"stdout","log":"#2","time":"2018-05-09T10:00:02Z"} +{"stream":"stdout","log":"#3","time":"2018-05-09T10:00:03Z"} ` - logContentPart2 = `{"source":"stdout","line":"#4","timestamp":"2018-05-09T10:00:04Z"} + logContentPart2 = `{"stream":"stdout","log":"#4","time":"2018-05-09T10:00:04Z"} ` - logContentPart3 = `{"source":"stderr","line":"#5","timestamp":"2018-05-09T10:00:05Z"} -{"source":"stderr","line":"#6","timestamp":"2018-05-09T10:00:06Z"} + logContentPart3 = `{"stream":"stderr","log":"#5","time":"2018-05-09T10:00:05Z"} +{"stream":"stderr","log":"#6","time":"2018-05-09T10:00:06Z"} ` )