MCPcopy Create free account
hub / github.com/coder/envbuilder / Writer

Function Writer

log/log.go:53–76  ·  view source on GitHub ↗

Writer returns an io.Writer that logs all writes in a separate goroutine. It is the responsibility of the caller to call the returned function to stop the goroutine.

(logf Func)

Source from the content-addressed store, hash-verified

51// It is the responsibility of the caller to call the returned
52// function to stop the goroutine.
53func Writer(logf Func) (io.Writer, func()) {
54 pipeReader, pipeWriter := io.Pipe()
55 doneCh := make(chan struct{})
56 go func() {
57 defer pipeWriter.Close()
58 defer pipeReader.Close()
59 scanner := bufio.NewScanner(pipeReader)
60 for {
61 select {
62 case <-doneCh:
63 return
64 default:
65 if !scanner.Scan() {
66 return
67 }
68 logf(LevelInfo, "%s", scanner.Text())
69 }
70 }
71 }()
72 closer := func() {
73 close(doneCh)
74 }
75 return pipeWriter, closer
76}

Callers 2

runFunction · 0.92
RunCacheProbeFunction · 0.92

Calls 1

CloseMethod · 0.80

Tested by

no test coverage detected