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.
This commit is contained in:
committed by
Arthur Barr
parent
05fe51d96d
commit
3599852fc1
@@ -623,9 +623,11 @@ func inspectTextLogs(t *testing.T, cli ce.ContainerInterface, ID string) string
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
text := scanner.Text()
|
text := scanner.Text()
|
||||||
if strings.HasPrefix(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{}
|
var e map[string]interface{}
|
||||||
json.Unmarshal([]byte(text), &e)
|
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 {
|
} else {
|
||||||
fmt.Fprintln(buf, text)
|
fmt.Fprintln(buf, text)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user