You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Anders D. Johnson, Kostya Kostyushko and Alexandr Zaytsev
With v3, you'll be able to override the out function... which will allow you to format the log output however you want. v2 doesn't including functionality like this, though
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 of debug is that it is a convention driven, runtime configurable logging tool. If I need to override something, then it is just another logging framework.
Well, a major goal of debug is to be minimal while also extensible. If you have a case where you need to write to a file, or write JSON to stdout, or move data to logstash via HTTP, debug should be able to support that without including the functionality into the core lib
Overwriting out, as I said before. You'll be able to stick whatever function you want on there, and do whatever you want with the output. It will be passed a string, which you parse into whatever form you want (JSON, etc) and then send wherever you want
Overwriting out, as I said before. You'll be able to stick whatever function you want on there, and do whatever you want with the output. It will be passed a string, which you parse into whatever form you want (JSON, etc) and then send wherever you want
That requires to have access to the debug instance. It is fine if my application and ALL of the dependencies share the same version of debug. However, if at least one of them does not, there is no way for me to control output format of that dependency from within my application.
I mean, by default, you aren't going to see any output if you are dealing with third-party libs. If you care about the output from third-party libs, and want a special format, it doesn't seem like a stretch to require you to install debug as a dep and overwrite the log function
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, using an env variable is good and all, but it requires additional surface area for the lib.... yet another configuration option that has to be well supported on every single platform running debug (node, all major browsers, electron, cordova, etc).
Standardized output to TTY and non-TTY interfaces on a variety of platforms with yet another output format isn't as simple as simply calling JSON.stringify
I'm looking for the same. Why the issue is closed?
Would be great to have output as JSON, many log parser works better with JSON format than custom text format..
Example of output could be:
Activity
thebigredgeek commentedon Apr 17, 2017
With v3, you'll be able to override the
outfunction... which will allow you to format the log output however you want. v2 doesn't including functionality like this, thoughgajus commentedon Apr 18, 2017
Well, overriding the functionality of
outis hardly a fix here. If I need to override something, I'd rather use a logging framework such as bunyan or winston. The convenience ofdebugis that it is a convention driven, runtime configurable logging tool. If I need to override something, then it is just another logging framework.thebigredgeek commentedon Apr 18, 2017
Well, a major goal of debug is to be minimal while also extensible. If you have a case where you need to write to a file, or write JSON to stdout, or move data to logstash via HTTP, debug should be able to support that without including the functionality into the core lib
gajus commentedon Apr 18, 2017
How .. ?
gajus commentedon Apr 18, 2017
The mere fact that the output can be multiline makes it impossible parse the logs in any reliable way.
thebigredgeek commentedon Apr 18, 2017
Overwriting
out, as I said before. You'll be able to stick whatever function you want on there, and do whatever you want with the output. It will be passed a string, which you parse into whatever form you want (JSON, etc) and then send wherever you wantgajus commentedon Apr 18, 2017
That requires to have access to the
debuginstance. It is fine if my application and ALL of the dependencies share the same version ofdebug. However, if at least one of them does not, there is no way for me to control output format of that dependency from within my application.thebigredgeek commentedon Apr 18, 2017
I mean, by default, you aren't going to see any output if you are dealing with third-party libs. If you care about the output from third-party libs, and want a special format, it doesn't seem like a stretch to require you to install debug as a dep and overwrite the log function
gajus commentedon Apr 18, 2017
This is year 2020.
lalalandthat usesdebug@v4.lalalanddependencyawesomestdlibusesdebug@3.How do I format logs of
awesomestdlibusing the proposedoutproperty override?gajus commentedon Apr 18, 2017
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
outmethod 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.
thebigredgeek commentedon Apr 18, 2017
Well, using an env variable is good and all, but it requires additional surface area for the lib.... yet another configuration option that has to be well supported on every single platform running debug (node, all major browsers, electron, cordova, etc).
gajus commentedon Apr 18, 2017
Don't understand the argument.
JSON.stringifyis part of the ECMA standard since 1.7.thebigredgeek commentedon Apr 18, 2017
Standardized output to TTY and non-TTY interfaces on a variety of platforms with yet another output format isn't as simple as simply calling
JSON.stringifyKostanos commentedon Dec 3, 2018
I'm looking for the same. Why the issue is closed?
Would be great to have output as JSON, many log parser works better with JSON format than custom text format..
Example of output could be:
This would fit to most of the log parsers that support JSON format logs.
Qix- commentedon Dec 3, 2018
Please see #582.
Kostanos commentedon Dec 3, 2018
Thank you @Qix- but could you please show example how output could be converted to JSON?
And how to make it as a standard in all files?
For those who is still need JSON as simple as it is, I'm checking this library: https://www.npmjs.com/package/pino
But would be great to have simple support for JSON in debug library (I have already so many scripts done with "debug")
For example something like this:
or this:
etc...
Qix- commentedon Dec 3, 2018
@Kostanos please post on that ticket, not here.
nervgh commentedon May 25, 2020
There is pino-debug.