Convert to "debug" library for debug logging #231
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of logging in
json-rules-engine
is extremely inefficient when debug logging is disabled (the most common [and default] case). Each debug statement constructs a new string of the debug message then checks a set of environment variables before ignoring the string all together.The "DEBUG" environment variable when set to "json-rules-engine" enables debug logging across the entire library and makes it difficult to know which file the messages are coming from.
This PR adds the extremely popular and lightweight debug library and converts all existing "debug" statements to the placeholder based syntax supported by "debug". Now when debugging is not enabled (the most common and default case), debug messages do not construct new strings and no additional overhead is added. If debug is enabled, the strings are now constructed using the standard debug formatters (and one additional "typeof o" formatter added in
debug.js
)"debug" supports both NodeJS runtimes and browsers and can be enabled using the same DEBUG environment variable. See the library link above for more information.