adzejs/adze

Support for pretty printing data to the terminal?

Closed this issue · 4 comments

Does adze support pretty printing JSON objects/arrays to the terminal? That could be really useful especially if JSON objects could be color highlighted.

Hi @evelant,

Are you requesting this feature when in "machineReadable" mode or just when generating a standard formatted log? Are you referring to the node terminal or the browser console? It's an interesting idea that I'm definitely willing to consider adding as a feature, but I just need some more specifics.

This could also be accomplished right now with a little extra code.

First you would need to set up a log listener on the shed.
Then you would generate your logs with the "silent" modifier. This will prevent them from printing in the standard way.
Then in your log listener you can capture all of the data you need in order to execute a pretty print.

Here's a stack overflow about how to format some JSON in a pretty format: https://stackoverflow.com/questions/5670752/how-can-i-pretty-print-json-using-node-js

Referring to node (I use react-native so the environment is similar to node). In development it would be useful to pretty format and highlight JSON log output. Right now I'm using a simple custom log wrapper that does a JSON.stringify and then piping my output in the shell to a formatting utility such as https://github.com/brocode/fblog (or pino-pretty etc). That works OK but unless I want to fork the external log formatters it's a bit rigid.

https://github.com/xpl/ololog is a nice approach for dev log tooling but unfortunately it's written in a really inscrutable style of plain JS that's almost downright hostile to Typescript and very difficult to extend/modify/debug.

I was curious if adze had an approach for pretty-printing logs in dev (or perhaps even later when consuming JSON output from production). I haven't been able to find a really great solution to this bit of dev tooling yet.

I think this would be a great feature for Adze to adopt as a log modifier. I'll label this as a feature request and hopefully include it in version 2 which will be coming soon.

Adze v2 now supports better formatting options!