From 3599852fc1863151c14d146febd6f0d80315614a Mon Sep 17 00:00:00 2001 From: "arthur.barr@uk.ibm.com" Date: Thu, 1 Jun 2023 14:42:47 +0100 Subject: [PATCH] Include timestamp in test output for JSON logs 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. --- test/container/docker_api_test_util.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/container/docker_api_test_util.go b/test/container/docker_api_test_util.go index e3a9f2c..143e04d 100644 --- a/test/container/docker_api_test_util.go +++ b/test/container/docker_api_test_util.go @@ -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) }