Write writes the given bytes to the line buffer, and increments the entries counter. If the buffer is full (entries == cap), it will be flushed, and the entries counter reset.
(p []byte)
| 31 | // Write writes the given bytes to the line buffer, and increments the entries counter. |
| 32 | // If the buffer is full (entries == cap), it will be flushed, and the entries counter reset. |
| 33 | func (l *BufferedLogger) Write(p []byte) (n int, err error) { |
| 34 | // when we've filled the buffer, flush it |
| 35 | if l.Size() >= l.cap { |
| 36 | // Flush resets the size to 0 |
| 37 | if err := l.Flush(); err != nil { |
| 38 | l.buf.Reset() |
| 39 | return 0, err |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | l.entries.Inc() |
| 44 | |
| 45 | return l.buf.Write(p) |
| 46 | } |
| 47 | |
| 48 | // Flush forces the buffer to be written to the underlying writer. |
| 49 | func (l *BufferedLogger) Flush() error { |