diff --git a/examples/flushing/.gitignore b/examples/flushing/.gitignore new file mode 100644 index 000000000..2383fed92 --- /dev/null +++ b/examples/flushing/.gitignore @@ -0,0 +1 @@ +myfile.log diff --git a/klog.go b/klog.go index 152f8a6bd..a4290d11d 100644 --- a/klog.go +++ b/klog.go @@ -873,6 +873,9 @@ func (l *loggingT) output(s severity.Severity, logger *logWriter, buf *buffer.Bu if logger.writeKlogBuffer != nil { logger.writeKlogBuffer(data) } else { + if len(data) > 0 && data[len(data)-1] == '\n' { + data = data[:len(data)-1] + } // TODO: set 'severity' and caller information as structured log info // keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line} if s == severity.ErrorLog { diff --git a/klog_test.go b/klog_test.go index 76303e068..7b6ebdb6f 100644 --- a/klog_test.go +++ b/klog_test.go @@ -1484,13 +1484,13 @@ func TestInfoWithLogr(t *testing.T) { msg: "foo", expected: testLogrEntry{ severity: severity.InfoLog, - msg: "foo\n", + msg: "foo", }, }, { msg: "", expected: testLogrEntry{ severity: severity.InfoLog, - msg: "\n", + msg: "", }, }} diff --git a/test/zapr.go b/test/zapr.go index 7b1594429..6c7e809fb 100644 --- a/test/zapr.go +++ b/test/zapr.go @@ -171,22 +171,22 @@ I output.go:] "odd WithValues" keyWithoutValue="(MISSING)" // klog.Info `I output.go:] "helloworld\n" -`: `{"caller":"test/output.go:","msg":"helloworld\n","v":0} +`: `{"caller":"test/output.go:","msg":"helloworld","v":0} `, // klog.Infoln `I output.go:] "hello world\n" -`: `{"caller":"test/output.go:","msg":"hello world\n","v":0} +`: `{"caller":"test/output.go:","msg":"hello world","v":0} `, // klog.Error `E output.go:] "helloworld\n" -`: `{"caller":"test/output.go:","msg":"helloworld\n"} +`: `{"caller":"test/output.go:","msg":"helloworld"} `, // klog.Errorln `E output.go:] "hello world\n" -`: `{"caller":"test/output.go:","msg":"hello world\n"} +`: `{"caller":"test/output.go:","msg":"hello world"} `, // klog.ErrorS @@ -201,12 +201,12 @@ I output.go:] "odd WithValues" keyWithoutValue="(MISSING)" // klog.V(1).Info `I output.go:] "hellooneworld\n" -`: `{"caller":"test/output.go:","msg":"hellooneworld\n","v":1} +`: `{"caller":"test/output.go:","msg":"hellooneworld","v":1} `, // klog.V(1).Infoln `I output.go:] "hello one world\n" -`: `{"caller":"test/output.go:","msg":"hello one world\n","v":1} +`: `{"caller":"test/output.go:","msg":"hello one world","v":1} `, // klog.V(1).ErrorS