Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-format log output as ndjson #5708

Merged
merged 2 commits into from
Oct 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions core/commands/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"bytes"
"encoding/json"
"fmt"
"io"

Expand Down Expand Up @@ -103,13 +104,28 @@ 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)
// Reformat the logs as ndjson
// TODO: remove this: #5709
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)
},
}

Expand Down