diff --git a/Readme.md b/Readme.md index e718f5be..500c37ef 100644 --- a/Readme.md +++ b/Readme.md @@ -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) diff --git a/node.js b/node.js index 1d392a81..e361486c 100644 --- a/node.js +++ b/node.js @@ -18,6 +18,7 @@ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; +exports.useDiff = useDiff; /** * Colors. @@ -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. */ @@ -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; } diff --git a/package.json b/package.json index b9f033a7..f9f1a9b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "2.2.0", + "version": "2.3.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git"