Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

truncate large/long debug output arguments #523

Merged
merged 2 commits into from
Oct 1, 2017

Conversation

iamjochem
Copy link
Contributor

@iamjochem iamjochem commented Sep 25, 2017

wrap the debug node_module so that large/long debug output args are always truncated (avoids potentially MBs of data being outout to console).

this PR adds a module that offers a transparent wrap for the 3rd-party debug module,
you just need to require ./utils/debug in place of debug itself.

the idea for this PR was originally discussed here: #521

there are a couple of unit tests included.

…ated (avoids potentially MBs of data being outout to console)
@luin
Copy link
Collaborator

luin commented Sep 25, 2017

Nice patch! However, it seems that these changes may have a impact on the performance even when the debug mode is off (e.g. truncating strings).

I just found out that the debug module supports custom formatters. What about define a custom formatter for the arguments?

For example:

const createDebug = require('debug');
createDebug.formatters.a = (v) => {
  return genRedactedString(v, len);
};

module.exports = createDebug;

@iamjochem
Copy link
Contributor Author

you are correct about the custom formatters - this is what I actually currently use to solve this issue in my own project.

the reason I chose not to use custom formatters here is because they are applied "module" wide ... i.e. you may very well be overriding existing custom formatters or applying them (without asking) to all instances of "debug" used in a project's own code and all it's other dependencies (assuming they use the same version) ... I felt that this was something to be avoided (it is unfortunate that debug does not support custom formatters per 'instance')

the fix for the potential performance hit is easy enough - I pushed a commit that make the debug call a no-op (basically performing the same check as is done in the debug module itself) ... what do think?

@luin
Copy link
Collaborator

luin commented Sep 25, 2017

Awesome! Makes sense to me. I'll do some tests this weekend, and merge then.

@luin luin self-requested a review September 25, 2017 18:53
@luin luin merged commit cf18554 into redis:master Oct 1, 2017
@luin
Copy link
Collaborator

luin commented Oct 1, 2017

Released as v3.2.0. 🍺

@iamjochem
Copy link
Contributor Author

@luin - thanks for merging, it's a goog feeling to start the week with a successful PR :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants