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: Steven Allen <steven@stebalien.com>
Steven Allen committed
Oct 30, 2018 at 17:26 UTC
68ac5170f1ff66479af447478c81ba03a0b103a0
1 file changed
+18
-4
core/commands/log.go
+18
-4
@@ -2,6 +2,7 @@ package commands
2
3
import (
4
"bytes"
5
+ "encoding/json"
6
"fmt"
7
"io"
8
@@ -103,13 +104,26 @@ Outputs event log messages (not other log messages) as they are generated.
104
105
Run: func(req cmds.Request, res cmds.Response) {
106
ctx := req.Context()
106
- r, w := io.Pipe()
107
+ r1, w1 := io.Pipe()
108
+ r2, w2 := io.Pipe()
109
go func() {
108
- defer w.Close()
110
+ defer w1.Close()
111
<-ctx.Done()
112
}()
111
- lwriter.WriterGroup.AddWriter(w)
112
- res.SetOutput(r)
113
+ go func() {
114
+ defer w2.Close()
115
+ decoder := json.NewDecoder(r1)
116
+ encoder := json.NewEncoder(w2)
117
+ for {
118
+ var obj interface{}
119
+ if decoder.Decode(&obj) != nil || encoder.Encode(obj) != nil {
120
+ return
121
+ }
122
+ }
123
+ }()
124
+
125
+ lwriter.WriterGroup.AddWriter(w1)
126
+ res.SetOutput(r2)
127
},
128
}
129