提交 68ac5170 作者: Steven Allen

re-format log output as ndjson

Apparently, js-ipfs-api expects this. Really, I'm not sure why js-ipfs-api even
cares about this endpoint but that's a different issue.

The real fix is to change back to ndjson in go-log but that would force us to
update every package (not good when we're trying to push out a release like
this).

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 d5c8fa50
......@@ -2,6 +2,7 @@ package commands
import (
"bytes"
"encoding/json"
"fmt"
"io"
......@@ -103,13 +104,26 @@ Outputs event log messages (not other log messages) as they are generated.
Run: func(req cmds.Request, res cmds.Response) {
ctx := req.Context()
r, w := io.Pipe()
r1, w1 := io.Pipe()
r2, w2 := io.Pipe()
go func() {
defer w.Close()
defer w1.Close()
<-ctx.Done()
}()
lwriter.WriterGroup.AddWriter(w)
res.SetOutput(r)
go func() {
defer w2.Close()
decoder := json.NewDecoder(r1)
encoder := json.NewEncoder(w2)
for {
var obj interface{}
if decoder.Decode(&obj) != nil || encoder.Encode(obj) != nil {
return
}
}
}()
lwriter.WriterGroup.AddWriter(w1)
res.SetOutput(r2)
},
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论