From 68ac5170f1ff66479af447478c81ba03a0b103a0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 30 Oct 2018 17:26:49 -0700 Subject: [PATCH 1/2] 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 --- core/commands/log.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/core/commands/log.go b/core/commands/log.go index 9d31f9c31e5..61f049d09fb 100644 --- a/core/commands/log.go +++ b/core/commands/log.go @@ -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) }, } From 16d70eac326eca45dd96ee7447afd548114e73d9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 31 Oct 2018 04:53:57 -0700 Subject: [PATCH 2/2] add a todo to remember to remove log reformatting License: MIT Signed-off-by: Steven Allen --- core/commands/log.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/commands/log.go b/core/commands/log.go index 61f049d09fb..72101e1664d 100644 --- a/core/commands/log.go +++ b/core/commands/log.go @@ -110,6 +110,8 @@ Outputs event log messages (not other log messages) as they are generated. defer w1.Close() <-ctx.Done() }() + // Reformat the logs as ndjson + // TODO: remove this: #5709 go func() { defer w2.Close() decoder := json.NewDecoder(r1)