debug
Advanced tools
Comparing version 0.7.4 to 0.8.0
@@ -20,13 +20,2 @@ /** | ||
(process.env.DEBUG || '') | ||
.split(/[\s,]+/) | ||
.forEach(function(name){ | ||
name = name.replace('*', '.*?'); | ||
if (name[0] === '-') { | ||
skips.push(new RegExp('^' + name.substr(1) + '$')); | ||
} else { | ||
names.push(new RegExp('^' + name + '$')); | ||
} | ||
}); | ||
/** | ||
@@ -54,3 +43,3 @@ * Colors. | ||
var isatty = tty.isatty(2); | ||
var isatty = tty.isatty(1); | ||
@@ -124,3 +113,3 @@ /** | ||
console.error.apply(this, arguments); | ||
console.log.apply(this, arguments); | ||
} | ||
@@ -133,3 +122,3 @@ | ||
+ ' ' + name + ' ' + fmt; | ||
console.error.apply(this, arguments); | ||
console.log.apply(this, arguments); | ||
} | ||
@@ -152,1 +141,23 @@ | ||
} | ||
/** | ||
* Enable specified `namespaces` for debugging. | ||
*/ | ||
debug.enable = function(namespaces) { | ||
namespaces.split(/[\s,]+/) | ||
.forEach(function(name){ | ||
name = name.replace('*', '.*?'); | ||
if (name[0] == '-') { | ||
skips.push(new RegExp('^' + name.substr(1) + '$')); | ||
} else { | ||
names.push(new RegExp('^' + name + '$')); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Enable namespaces listed in `process.env.DEBUG` initially. | ||
*/ | ||
debug.enable(process.env.DEBUG || ''); |
{ | ||
"name": "debug" | ||
, "version": "0.7.4" | ||
, "version": "0.8.0" | ||
, "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" } | ||
@@ -15,11 +15,4 @@ , "description": "small debugging utility" | ||
"lib/debug.js", | ||
"debug.js", | ||
"index.js" | ||
"debug.js" | ||
] | ||
, "component": { | ||
"scripts": { | ||
"debug/index.js": "index.js", | ||
"debug/debug.js": "debug.js" | ||
} | ||
} | ||
} |
@@ -14,3 +14,3 @@ # debug | ||
With `debug` you simply invoke the exported function to generate your debug function, passing it a name which will determine if a noop function is returned, or a decorated `console.error`, so all of the `console` format string goodies you're used to work fine. A unique color is selected per-function for visibility. | ||
Example _app.js_: | ||
@@ -61,14 +61,13 @@ | ||
When stderr is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below: | ||
_(NOTE: Debug now uses stderr instead of stdout, so the correct shell command for this example is actually `DEBUG=* node example/worker 2> out &`)_ | ||
When stdout is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below: | ||
![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) | ||
## Conventions | ||
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. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". | ||
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. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". | ||
## 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:*`, or to run everything using this module simply use `DEBUG=*`. | ||
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=*`. | ||
@@ -79,3 +78,3 @@ 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:". | ||
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()`. | ||
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()`. | ||
@@ -95,3 +94,3 @@ ```js | ||
## License | ||
## License | ||
@@ -98,0 +97,0 @@ (The MIT License) |
232
9880
4
115