logWriter creates a WriteCloser that will log each line of text at the given level. The WriteCloser must be closed by the caller to end logging, after which the returned channel will be closed to indicate that logging of the written data has finished. Failure to close the WriteCloser will leak a g
(sink logSink, level proto.LogLevel)
| 601 | // by the caller to end logging, after which the returned channel will be closed to indicate that logging of the written |
| 602 | // data has finished. Failure to close the WriteCloser will leak a goroutine. |
| 603 | func logWriter(sink logSink, level proto.LogLevel) (io.WriteCloser, <-chan any) { |
| 604 | r, w := io.Pipe() |
| 605 | done := make(chan any) |
| 606 | go readAndLog(sink, r, done, level) |
| 607 | return w, done |
| 608 | } |
| 609 | |
| 610 | func readAndLog(sink logSink, r io.Reader, done chan<- any, level proto.LogLevel) { |
| 611 | defer close(done) |