Permalink
Browse files

Added wildcard support

  • Loading branch information...
1 parent 497a088 commit 0620d027cb48b38646b8a94092a82a971abdb60b @tj tj committed Jan 22, 2012
Showing with 25 additions and 2 deletions.
  1. +4 −0 Readme.md
  2. +10 −0 example/wildcards.js
  3. +11 −2 lib/debug.js
View
@@ -71,6 +71,10 @@ setInterval(function(){
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names.
+## Wildcards
+
+ 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:*`.
+
## License
(The MIT License)
View
@@ -0,0 +1,10 @@
+
+var debug = {
+ foo: require('../')('test:foo'),
+ bar: require('../')('test:bar'),
+ baz: require('../')('test:baz')
+};
+
+debug.foo('foo')
+debug.bar('bar')
+debug.baz('baz')
View
@@ -27,7 +27,12 @@ exports.version = '0.1.0';
* Enabled debuggers.
*/
-var names = (process.env.DEBUG || '').split(/[\s,]+/);
+var names = (process.env.DEBUG || '')
+ .split(/[\s,]+/)
+ .map(function(name){
+ name = name.replace('*', '.*?');
+ return new RegExp('^' + name + '$');
+ });
/**
* Colors.
@@ -67,7 +72,11 @@ function color() {
*/
function debug(name) {
- if (!~names.indexOf(name)) return function(){};
+ var match = names.some(function(re){
+ return re.test(name);
+ });
+
+ if (!match) return function(){};
var c = color();
function colored(fmt) {

3 comments on commit 0620d02

Owner

Yaaaayyyy!!!! I proposed this to you a while back but you weren't too into it. What changed your mind?

Owner
tj replied Jan 22, 2012

dunno haha was just bored this morning waiting for the flight, I think both you and guillermo wanted it so might as well

Owner
tj replied Jan 22, 2012

another thing we were thinking was maybe var debug = require('debug') would take the package name and then append :<basename> so lib/middleware/compress.js would have connect:compress, i dunno, probably be too cute

Please sign in to comment.