I'd like my program to write to its stderr a log that is simultaneously human and machine readable.
Requirements:
- A log is a stream of messages. I.e. I can't write just one big xml or json document. Every message has to be parseable separately without requiring an incremental parser or generator.
- tty detection and log format selection switches are considered cheating for the purposes of this question. I want the same exact output to be simultaneously human and machine readable.
- No postprocessing for the same reasons as 2
- No ad hoc formats. I don't want the consumer to have to write a parser. Not even a trivial one.
- No formats that are too obscure. There must be a library to parse this format in the top 10 most popular general purpose programming languages and the library must be able to parse the entire log into a stream of messages out of the box without requiring the consumer to massage the data.
Pretty JSON fails 5 - most JSON parsing APIs cannot parse multiple concatenated JSON documents.
JSON Lines is not human readable especially if it contains nested data because the entire log entry ends up on a single line.
It appears that application/json-seq (RFC 7464) does allow for the JSON texts to be pretty printed (human readable) while only requiring very simple parsing on top of a regular JSON decoder. This is the closest one yet.
Post-mortem
I ended up rethinking my approach: log jsonlines - easiest to generate and consume, post-process with en external pretty-printer such as jq .
for human consumption.