Checking systemd service logs in a JSON format might be a bit annoying. The output is far from readable, but AWK comes to help. The key is to use the "{" character as a separator, and reusing it in the printf command.
In my case, I had to check the mev-boost outputting in JSON format and used the following command to make the output more readable.
journalctl -u mev-boost --since "2025-09-22 00:00:00" | \ awk -F{ \ '$0 !~ /io.ReadCloser/ { printf ( "%s%s\n" ,FS ,$2) }' | \ jq .
The first line limits the output of journal logs to unit `mev_boost` from 22nd September 2025. Second and third line direct AWK to split each line on the "{" character, and processes only lines which do not contain the string "io.ReadCloser". The lines with the string are not proper JSON. Next, the second field/substring is printed, but prefixed with the field separate ("FS"). Otherwise, the output will not be a valid JSON, because the opening "{" is used a separator. Such formatted line is then sent to jq. In the example, jq just prints the output in a human friendly way, but it can be used to query the output.
No comments:
Post a Comment