You can log structured data to systemd
and then view it as is or in json format
Let's say we log key-value pairs in json format
systemd-cat -t "struct_logs" echo '{"key1": "value1", "key2": 1234}'
Then we read them as is
sudo journalctl -t 'struct_logs' --lines 1 --no-pager
Apr 30 21:46:14 linux-ar struct_logs[17455]: {"key1": "value1", "key2": 1234}
Or in json format
sudo journalctl -t 'struct_logs' --lines 1 --no-pager -o json-pretty
{
"__CURSOR" : "s=b6d07ffffffffff2787cea140a0db88a5;i=db8;b=c9b2132ffffffffe5807625fe;m=9fa5b3f81;t=58fffffff87eab;x=6402818ea7e32a5b",
"__REALTIME_TIMESTAMP" : "1556671574343339",
"__MONOTONIC_TIMESTAMP" : "42854989697",
"_BOOT_ID" : "fffffffffffff24ec7a237b5e5807625fe",
"PRIORITY" : "6",
"_MACHINE_ID" : "fffffffffff66c86aaaaaaaaaa",
"_HOSTNAME" : "linux-ar",
"_TRANSPORT" : "stdout",
"_UID" : "1000",
"_GID" : "100",
"SYSLOG_IDENTIFIER" : "struct_logs",
"MESSAGE" : "{\"key1\": \"value1\", \"key2\": 1234}",
"_PID" : "17455"
}
Going further you can recover your exact log messages with the help of jq
sudo journalctl -t 'struct_logs' --lines 1 --no-pager -o json-pretty | jq -r '.MESSAGE'
{"key1": "value1", "key2": 1234}
It could be possible also to log custom keys provided that the user has the proper rights to do that. A service should be able to do that
sudo logger --journald <<end
MESSAGE_ID=67feb6ffbaf24c5cbec13c008dd72309
MESSAGE=The dogs bark, but the caravan goes on.
SYSLOG_IDENTIFIER=struct_logs
KEY=bark
VALUE=goes on
end
Hope this helps.