Is it possible to configure runner to output logs in JSON format? #3065
Replies: 2 comments
-
|
It would be awesome to have this option. Or at least something that makes each log entry print on a single line. Right now JSONs are sometimes output to the logs, but each json entry is on a separate line, making them very hard to parse. |
Beta Was this translation helpful? Give feedback.
-
|
As far as I know, the runner does not currently expose a setting to emit job logs as JSON For application-level structured logging, the most practical workaround is to emit JSONL / newline-delimited JSON: one compact JSON object per line. The GitHub Actions log viewer is line-oriented, so pretty-printed JSON will be split across multiple log lines and becomes harder to parse For example, avoid this: {
"level": "info",
"message": "something happened"
}Prefer this: {"level":"info","message":"something happened"}If you already have JSON and want to print it as one line, you can usually compact it before writing to stdout: jq -c . result.jsonFor post-processing after the run, GitHub also provides an API endpoint to download job logs: GET /repos/{owner}/{repo}/actions/jobs/{job_id}/logs
Accept: application/vnd.github+jsonThe downloaded logs are still plain text, not JSON, but this can be useful if you want to parse or ship them elsewhere after the workflow completes For structured diagnostics inside a workflow, GitHub workflow commands such as |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Is it possible for the runner to emit logs in JSON format? The text format makes filtering and searching very difficult.
Beta Was this translation helpful? Give feedback.
All reactions