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

node: allow msDiff disable #208

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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
23 changes: 9 additions & 14 deletions dist/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ module.exports = function(val, options){
*/

function parse(str) {
str = '' + str;
if (str.length > 10000) return;
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
if (!match) return;
var n = parseFloat(match[1]);
Expand Down Expand Up @@ -336,17 +338,10 @@ exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;

/**
* Use chrome.storage.local if we are in an app
*/

var storage;

if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
storage = chrome.storage.local;
else
storage = localstorage();
exports.storage = 'undefined' != typeof chrome
&& 'undefined' != typeof chrome.storage
? chrome.storage.local
: localstorage();

/**
* Colors.
Expand Down Expand Up @@ -454,9 +449,9 @@ function log() {
function save(namespaces) {
try {
if (null == namespaces) {
storage.removeItem('debug');
exports.storage.removeItem('debug');
} else {
storage.debug = namespaces;
exports.storage.debug = namespaces;
}
} catch(e) {}
}
Expand All @@ -471,7 +466,7 @@ function save(namespaces) {
function load() {
var r;
try {
r = storage.debug;
r = exports.storage.debug;
} catch(e) {}
return r;
}
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