
Always Log JSON - Hedja
https://jahed.io/2018/07/05/always-log-to-json/
======
badrabbit
Nothing against json but I disagree with that conclusion.

There are tools that support only syslog for example.

Sometimes your aim is to log a large number of events,sometimes you want to
log a lot but with less frequency. Syslog or maybe even binary logging might
make sense for high volume events due to how the extra json formatting adds up
quickly (and that could have a financial cost to it!!). If you want to log a
lot of events but the frequency needs to be low due to resource
constraints,then json may or may not add to your problem. It may be a problem
as an intrmediate format but not so much if the final processed log is also
json. If the resource bottleneck is caused by the log processing stage then
there almost certainly be a better format. But I am not speaking strictly of
JS code like the author.

~~~
Hedja
Author here.

Yes, my conclusion's a bit blunt. I guess the broader takeaway is to not
generate log lines in your business logic but instead to use a common API for
events so that changing outputs (e.g. to syslog or some other standard) is
straight forward, as shown in the example code with the concept of
"reporters".

You can also pipe the output from JSON to syslog if format is the main concern
and not performance. Like pino-syslog[1] shows.

[1] [https://github.com/pinojs/pino-syslog](https://github.com/pinojs/pino-
syslog)

