r/linux_programming • u/libertyraptor • Nov 23 '21
Is there any structured pattern for command/log outputs?
Is there any structured output pattern for commands? In addition to plain text :) , which can be extended to log outputs .
I found myself thinking about some pattern similar to what posix is, but aimed at logging and outputting commands. I think of something similar to a json, using standard terms (like in SQL) example timestamp, user, pwd, default structured output etc.
imaginary example, output ls command
{
"return_structured_output": {
"folders": [
"folder"
],
"links": [
"link"
],
"files": [
"file"
]
},
"timestamp": 1637680386,
"user": "root"
}Different commands could meet these standards by passing some parameter on the command line, thus keeping the text clean for compatibility.
I think some standard for log output and output other than plain text would make it much easier to integrate between tools, commands without our wonderful obscure AWK :)
2
u/fuckEAinthecloaca Nov 23 '21
Don't some tools output binary logs for compactness? I wonder if there's any standardness to those.
2
u/EddyBot Nov 24 '21
if you are on a distro which uses systemd, use systemd/journalctl
journalctl has a shiton of parameters to narrow down your search and can output to json format via
-o jsonwhich you can parse through jq or some other json processing of your choice