Skip to content

Commit

Permalink
Merge pull request #1 from cheshirecatalyst/feature/disablMsDiff
Browse files Browse the repository at this point in the history
node: allow msDiff disable
  • Loading branch information
world committed Jun 1, 2016
2 parents 39ecd87 + 30c21be commit b88fe8b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Then, run the program to be debugged as usual.

## Millisecond diff

When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. Can be disabled with `DEBUG_DIFF=0`

![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png)

Expand Down
21 changes: 17 additions & 4 deletions node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.useDiff = useDiff;

/**
* Colors.
Expand Down Expand Up @@ -53,6 +54,18 @@ function useColors() {
}
}

/**
* Allow disabling ms diff, enabled by default.
*/

function useDiff() {
var diff = (process.env.DEBUG_DIFF || '').trim().toLowerCase();
return '0' !== diff
&& 'no' !== diff
&& 'false' !== diff
&& 'disabled' !== diff;
}

/**
* Map %o to `util.inspect()`, since Node doesn't do that out of the box.
*/
Expand Down Expand Up @@ -86,14 +99,14 @@ function formatArgs() {

if (useColors) {
var c = this.color;

var timeStamp = useDiff() ? ' +' + exports.humanize(this.diff) : ''
args[0] = ' \u001b[3' + c + ';1m' + name + ' '
+ '\u001b[0m'
+ args[0] + '\u001b[3' + c + 'm'
+ ' +' + exports.humanize(this.diff) + '\u001b[0m';
+ timeStamp + '\u001b[0m';
} else {
args[0] = new Date().toUTCString()
+ ' ' + name + ' ' + args[0];
var timeStamp = useDiff() ? new Date().toUTCString() + ' ' : ''
args[0] = timeStamp + name + ' ' + args[0];
}
return args;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "debug",
"version": "2.2.0",
"version": "2.3.0",
"repository": {
"type": "git",
"url": "git://github.com/visionmedia/debug.git"
Expand Down

0 comments on commit b88fe8b

Please sign in to comment.