MCPcopy
hub / github.com/uber-go/zap / writeLine

Method writeLine

zapio/writer.go:91–116  ·  view source on GitHub ↗

writeLine writes a single line from the input, returning the remaining, unconsumed bytes.

(line []byte)

Source from the content-addressed store, hash-verified

89// writeLine writes a single line from the input, returning the remaining,
90// unconsumed bytes.
91func (w *Writer) writeLine(line []byte) (remaining []byte) {
92 idx := bytes.IndexByte(line, '\n')
93 if idx < 0 {
94 // If there are no newlines, buffer the entire string.
95 w.buff.Write(line)
96 return nil
97 }
98
99 // Split on the newline, buffer and flush the left.
100 line, remaining = line[:idx], line[idx+1:]
101
102 // Fast path: if we don't have a partial message from a previous write
103 // in the buffer, skip the buffer and log directly.
104 if w.buff.Len() == 0 {
105 w.log(line)
106 return
107 }
108
109 w.buff.Write(line)
110
111 // Log empty messages in the middle of the stream so that we don't lose
112 // information when the user writes "foo\n\nbar".
113 w.flush(true /* allowEmpty */)
114
115 return remaining
116}
117
118// Close closes the writer, flushing any buffered data in the process.
119//

Callers 1

WriteMethod · 0.95

Calls 4

logMethod · 0.95
flushMethod · 0.95
WriteMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected