Add ability to format `debug` as JSON output
See original GitHub issueI’d like there to be an option (controllable using environment variables) that would make debug
module print JSON output instead of plain text.
This at the moment can be achieved using a module such as debug-to-json
(@ping yoshuawuyts). The problem with the pipe solution is that it is not always easy to modify the command used to start the program (e.g. How to append an argument to a container command?).
Maybe I am doing something wrong, but (in a large deployment) logs coming via debug
are quite useless (“large deployment” being a Kubernetes cluster with filebeat + ELK used for logging). [I suppose it is possible to reconize debug output in logstash and convert it to JSON?]
Being able to configure debug
output with environment variable would greatly alleviate the difficulty of log processing here, e.g.
DEBUG_FORMAT=json
The other thing to note here is that certain log aggregation methods (filebeat) require that logs come in one-per-line. Plain text output does not guarantee this; JSON can.
Furthermore, the JSON format could be used to supplement debug output with meta information such as package name, version. This can be a controllable option via environment variables too.
I’d be happy to raise a PR.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:18 (8 by maintainers)
Top GitHub Comments
If you really want to depend on overriding the output method, then use a global variable, e.g.
Then whatever app that wants to override the
out
method would need to include this script prior to executing any code, e.g.node -r debug-format.js my-app.js
.Unlike the proposed approach, this approach can be work with multiple versions of debug in a backwards compatible way.
I don’t think thats a right approach. It is an overkill. Simply allowing to output content in JSON format using ENV as configuration would be enough.
Well, overriding the functionality of
out
is hardly a fix here. If I need to override something, I’d rather use a logging framework such as bunyan or winston. The convenience ofdebug
is that it is a convention driven, runtime configurable logging tool. If I need to override something, then it is just another logging framework.