Skip to content

Commit

Permalink
Include timestamp in test output for JSON logs
Browse files Browse the repository at this point in the history
For a failing test, JSON log output from a container is abridged to just include the message text.  This change adds the timestamp as well.
  • Loading branch information
arthurbarr committed Jun 5, 2023
1 parent 05fe51d commit 3599852
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/container/docker_api_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,11 @@ func inspectTextLogs(t *testing.T, cli ce.ContainerInterface, ID string) string
for scanner.Scan() {
text := scanner.Text()
if strings.HasPrefix(text, "{") {
// If it's a JSON log message, it makes it hard to debug the test, as the JSON
// is embedded in the long test output. So just summarize the JSON instead.
var e map[string]interface{}
json.Unmarshal([]byte(text), &e)
fmt.Fprintf(buf, "{\"message\": \"%v\", ...}\n", e["message"])
fmt.Fprintf(buf, "{\"ibm_datetime\": \"%v\", \"message\": \"%v\", ...}\n", e["ibm_datetime"], e["message"])
} else {
fmt.Fprintln(buf, text)
}
Expand Down

0 comments on commit 3599852

Please sign in to comment.