Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a0cbe33
fix(zapio): add carriage return support in Writer
lyydsheep Mar 13, 2026
35d389b
fix(zapio): remove unused sepIsCR variable
lyydsheep Mar 13, 2026
8ec90f3
fix(zapio): fix comment placement for better readability
lyydsheep Mar 13, 2026
4235077
fix(zapio): remove extra blank line for better readability
lyydsheep Mar 14, 2026
d18ba5a
fix(zapio): improve comment style for better readability
lyydsheep Mar 14, 2026
e72febf
fix(zapio): address reviewer feedback for carriage return support
lyydsheep Mar 14, 2026
17a07b5
fix(zapio): fix missing return value in writeLine fast path
lyydsheep Mar 14, 2026
3bbbcd9
fix(zapio): correct carriage return handling per review feedback
lyydsheep Mar 14, 2026
438a077
fix(zapio): fix separator detection logic for stand-alone carriage re…
lyydsheep Mar 15, 2026
8d883ce
docs(zapio): update Write docstring to clarify carriage return handling
lyydsheep Mar 15, 2026
0702137
fix(zapio): clarify comments for separator detection logic
lyydsheep Mar 16, 2026
d1a0764
fix(zapio): handle nlIdx == crIdx edge case in separator detection
lyydsheep Mar 16, 2026
c1b89f2
fix(zapio): fix fast path and buffer logging logic
lyydsheep Mar 17, 2026
42facf6
fix(zapio): handle consecutive newlines properly
lyydsheep Mar 17, 2026
3097084
fix(zapio): remove ineffectual assignment to pass lint
lyydsheep Mar 17, 2026
d7fc916
test(zapio): fix test case to properly validate CR behavior
lyydsheep Mar 18, 2026
cc755ef
refactor(zapio): simplify separator detection logic
lyydsheep Mar 18, 2026
e3211ce
fix(zapio): use consistent variable declaration style
lyydsheep Mar 19, 2026
e4557ae
fix(zapio): final polish for carriage return support
lyydsheep Mar 19, 2026
5c0abff
fix(zapio): improve variable naming clarity
lyydsheep Mar 19, 2026
1a0ce47
fix(zapio): carriage return should discard buffer not flush
lyydsheep Mar 24, 2026
baf7755
fix(zapio): cr should not flush, only reset buffer
lyydsheep Mar 24, 2026
db4f17a
fix(zapio): address sywhang review feedback
lyydsheep Mar 24, 2026
64b32c1
fix(zapio): do not flush on bare carriage return
lyydsheep Mar 24, 2026
9b76f1a
fix(zapio): address sywhang review feedback - cr should not flush
lyydsheep Mar 24, 2026
470fe4e
fix(zapio): cr should reset buffer not flush (#1536)
lyydsheep Mar 25, 2026
260639a
fix(zapio): address sywhang style feedback and remove flush-on-cr beh…
lyydsheep Mar 25, 2026
9e49c84
fix(zapio): address sywhang review feedback - remove irrelevant comments
lyydsheep Mar 25, 2026
5d108f5
fix(zapio): do not log on bare carriage return, only reset buffer
lyydsheep Mar 25, 2026
97a9806
fix(zapio): address sywhang review style feedback - no changes needed
lyydsheep Mar 25, 2026
fbf926c
fix(zapio): do not flush on bare carriage return
lyydsheep Mar 25, 2026
d90de37
fix(zapio): address sywhang review feedback
lyydsheep Mar 25, 2026
e4d8833
fix(zapio): address sywhang review feedback - clean up style and cr h…
lyydsheep Mar 25, 2026
268bfb2
fix(zapio): cleanup per reviewer feedback
lyydsheep Mar 25, 2026
c2d83a4
fix(zapio): address sywhang review - bare cr should not flush
lyydsheep Mar 25, 2026
b42aa4e
fix(zapio): address remaining sywhang review feedback
lyydsheep Mar 25, 2026
5000e27
fix(zapio): use explicit return values instead of named returns
lyydsheep Mar 25, 2026
a8c08bb
fix(zapio): bare cr resets buffer without flushing per sywhang review
lyydsheep Mar 25, 2026
1de48fd
fix(zapio): address sywhang review feedback
lyydsheep Mar 26, 2026
6ff89e7
fix(zapio): address sywhang review feedback - cr must not flush
lyydsheep Mar 26, 2026
dab0750
fix(zapio): address sywhang review feedback - bare cr resets buffer w…
lyydsheep Mar 26, 2026
9a0a65e
fix(zapio): address sywhang review feedback - bare cr should not prod…
lyydsheep Mar 26, 2026
d28f62a
fix(zapio): address sywhang style feedback
lyydsheep Mar 26, 2026
e27e054
fix(zapio): address sywhang review feedback
lyydsheep Mar 26, 2026
16e6271
fix(zapio): address sywhang style review feedback
lyydsheep Mar 26, 2026
6587407
fix(zapio): address sywhang review feedback - revert style changes
lyydsheep Mar 26, 2026
a32d31f
fix(zapio): add carriage return support - minimal change approach
lyydsheep Mar 26, 2026
523f5d6
fix(zapio): address sywhang review comments
lyydsheep Mar 26, 2026
d8b61c7
fix(zapio): address all sywhang review comments
lyydsheep Mar 26, 2026
c2787ff
fix(zapio): add carriage return support
lyydsheep Mar 26, 2026
f22e012
fix(zapio): address sywhang review feedback
lyydsheep Mar 26, 2026
ed41735
fix(zapio): address reviewer feedback - bare \r resets buffer without…
lyydsheep Mar 27, 2026
b759c7c
fix(zapio): resolve merge conflict in writer.go - keep CR support imp…
lyydsheep Mar 27, 2026
2e6381d
fix(zapio): address sywhang review feedback
lyydsheep Mar 27, 2026
cddb026
fix(zapio): address sywhang final review feedback
lyydsheep Mar 27, 2026
ba1cdd7
fix(zapio): address sywhang review feedback - bare cr resets buffer w…
lyydsheep Mar 27, 2026
98279d1
fix(zapio): address sywhang review feedback - bare cr must not flush
lyydsheep Mar 27, 2026
5a13381
fix(zapio): address sywhang review feedback - bare cr must not flush
lyydsheep Mar 27, 2026
307b6fe
fix(zapio): address sywhang review feedback - cr resets buffer only, …
lyydsheep Mar 27, 2026
568ddd2
fix(zapio): address remaining sywhang review style feedback
lyydsheep Mar 27, 2026
c14b533
fix(zapio): address all sywhang review comments
lyydsheep Mar 27, 2026
388032b
fix(zapio): address sywhang review comments precisely
lyydsheep Mar 28, 2026
47fbd03
fix(zapio): address all sywhang review comments
lyydsheep Mar 28, 2026
425c136
fix(zapio): address sywhang review feedback
lyydsheep Mar 28, 2026
180ae6b
fix(zapio): address sywhang review feedback
lyydsheep Mar 28, 2026
249069a
fix(zapio): address sywhang review comments
lyydsheep Mar 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions zapio/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ func (w *Writer) Write(bs []byte) (n int, err error) {
// unconsumed bytes.
func (w *Writer) writeLine(line []byte) (remaining []byte) {
idx := bytes.IndexByte(line, '\n')
crIdx := bytes.IndexByte(line, '\r')

if crIdx >= 0 && (idx < 0 || crIdx < idx) && (crIdx+1 == len(line) || line[crIdx+1] != '\n') {
w.buff.Reset()
return line[crIdx+1:]
}

// Handle \r\n sequences - these are line terminators that should log
if crIdx >= 0 && crIdx+1 < len(line) && line[crIdx+1] == '\n' {
if w.buff.Len() == 0 {
w.log(line[:crIdx])
} else {
w.buff.Write(line[:crIdx])
w.flush(true)
}
return line[crIdx+2:]
}

if idx < 0 {
// If there are no newlines, buffer the entire string.
w.buff.Write(line)
Expand All @@ -110,7 +128,7 @@ func (w *Writer) writeLine(line []byte) (remaining []byte) {

// Log empty messages in the middle of the stream so that we don't lose
// information when the user writes "foo\n\nbar".
w.flush(true /* allowEmpty */)
w.flush(true)

return remaining
}
Expand All @@ -129,7 +147,7 @@ func (w *Writer) Sync() error {
// Don't allow empty messages on explicit Sync calls or on Close
// because we don't want an extraneous empty message at the end of the
// stream -- it's common for files to end with a newline.
w.flush(false /* allowEmpty */)
w.flush(false)
return nil
}

Expand Down
45 changes: 45 additions & 0 deletions zapio/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,51 @@ func TestWriter(t *testing.T) {
{Level: zap.InfoLevel, Message: ""},
},
},
{
desc: "carriage return newline sequence creates single line break",
writes: []string{
"foo\r\nbar\r\n",
},
want: []zapcore.Entry{
{Level: zap.InfoLevel, Message: "foo"},
{Level: zap.InfoLevel, Message: "bar"},
},
},
{
desc: "mixed newlines and carriage returns",
writes: []string{
"foo\nbar\r\rbaz\r\nqux\n",
},
want: []zapcore.Entry{
{Level: zap.InfoLevel, Message: "foo"},
{Level: zap.InfoLevel, Message: "baz"},
{Level: zap.InfoLevel, Message: "qux"},
},
},
{
desc: "carriage return with buffered content",
writes: []string{
"foo",
"ba",
"r\rqux",
"\n",
},
want: []zapcore.Entry{
{Level: zap.InfoLevel, Message: "qux"},
},
},
{
desc: "carriage return newline with buffered content",
writes: []string{
"foo",
"ba",
"r\r\nqux\r\n",
},
want: []zapcore.Entry{
{Level: zap.InfoLevel, Message: "foobar"},
{Level: zap.InfoLevel, Message: "qux"},
},
},
}

for _, tt := range tests {
Expand Down