debug: add an enabled flag to the returned debug function

So that you can do things conditionally if debug mode is enabled.

Closes #11.
This commit is contained in:
Nathan Rajlich 2012-03-16 14:54:37 -07:00
parent 3d03d65ea6
commit a9261144ff

View File

@ -105,17 +105,20 @@ function humanize(ms) {
*/
function debug(name) {
function disabled(){}
disabled.enabled = false;
var match = skips.some(function(re){
return re.test(name);
});
if (match) return function(){};
if (match) return disabled;
match = names.some(function(re){
return re.test(name);
});
if (!match) return function(){};
if (!match) return disabled;
var c = color();
function colored(fmt) {
@ -137,6 +140,8 @@ function debug(name) {
console.error.apply(this, arguments);
}
colored.enabled = plain.enabled = true;
return isatty
? colored
: plain;