From e70fcc38638f1699edeac4902a3667719d5cef20 Mon Sep 17 00:00:00 2001 From: Vinay Pulim Date: Tue, 7 Feb 2012 14:14:03 -0500 Subject: [PATCH 1/3] added support for "-" prefix in DEBUG --- lib/debug.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/debug.js b/lib/debug.js index 740ebb8..1be8b66 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -27,11 +27,19 @@ exports.version = '0.5.0'; * Enabled debuggers. */ -var names = (process.env.DEBUG || '') +var names = [], + skips = []; + +(process.env.DEBUG || '') .split(/[\s,]+/) - .map(function(name){ + .forEach(function(name){ name = name.replace('*', '.*?'); - return new RegExp('^' + name + '$'); + if (name[0] === '-') { + skips.push(new RegExp('^' + name.substr(1) + '$')); + } + else { + names.push(new RegExp('^' + name + '$')); + } }); /** @@ -97,7 +105,13 @@ function humanize(ms) { */ function debug(name) { - var match = names.some(function(re){ + var match = skips.some(function(re){ + return re.test(name); + }); + + if (match) return function(){}; + + match = names.some(function(re){ return re.test(name); }); From 883f44558c3ba91eb550b0760bd03db57cf60aff Mon Sep 17 00:00:00 2001 From: Vinay Pulim Date: Tue, 7 Feb 2012 18:08:28 -0500 Subject: [PATCH 2/3] support "-" prefix on the client --- debug.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/debug.js b/debug.js index e586b6a..b2f0798 100644 --- a/debug.js +++ b/debug.js @@ -39,6 +39,7 @@ function debug(name) { */ debug.names = []; +debug.skips = []; /** * Enables a debug mode by name. This can include modes @@ -56,7 +57,12 @@ debug.enable = function(name) { for (var i = 0; i < len; i++) { name = split[i].replace('*', '.*?'); - debug.names.push(new RegExp('^' + name + '$')); + if (name[0] === '-') { + debug.skips.push(new RegExp('^' + name.substr(1) + '$')); + } + else { + debug.names.push(new RegExp('^' + name + '$')); + } } }; @@ -98,6 +104,11 @@ debug.humanize = function(ms) { */ debug.enabled = function(name) { + for (var i = 0, len = debug.skips.length; i < len; i++) { + if (debug.skips[i].test(name)) { + return false; + } + } for (var i = 0, len = debug.names.length; i < len; i++) { if (debug.names[i].test(name)) { return true; From d656d2fc2bc94fefc5ed3d5020d5e0bb152965f3 Mon Sep 17 00:00:00 2001 From: Vinay Pulim Date: Wed, 8 Feb 2012 11:48:30 -0500 Subject: [PATCH 3/3] updated docs --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 93e2957..419fcdf 100644 --- a/Readme.md +++ b/Readme.md @@ -85,6 +85,8 @@ setInterval(function(){ The "*" character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect.compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`. + You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=* -connect:*` would include all debuggers except those starting with "connect:". + ## Browser support Debug works in the browser as well, currently persisted by `localStorage`. For example if you have `worker:a` and `worker:b` as shown below, and wish to debug both type `debug.enable('worker:*')` in the console and refresh the page, this will remain until you disable with `debug.disable()`.