change from stderr to stdout

This commit is contained in:
TJ Holowaychuk 2014-03-30 08:59:20 -07:00
parent db73b661fd
commit 491eea3b33
2 changed files with 10 additions and 11 deletions

View File

@ -11,7 +11,7 @@ $ npm install debug
## Usage
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_:
```js
@ -57,14 +57,13 @@ setInterval(function(){
![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png)
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
@ -74,7 +73,7 @@ setInterval(function(){
## 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()`.
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()`.
```js
a = debug('worker:a');
@ -89,7 +88,7 @@ setInterval(function(){
}, 1200);
```
## License
## License
(The MIT License)

View File

@ -39,7 +39,7 @@ var prevColor = 0;
* Is stdout a TTY? Colored output is disabled when `true`.
*/
var isatty = tty.isatty(2);
var isatty = tty.isatty(1);
/**
* Select a color.
@ -108,7 +108,7 @@ function debug(name) {
+ fmt + '\u001b[3' + c + 'm'
+ ' +' + humanize(ms) + '\u001b[0m';
console.error.apply(this, arguments);
console.log.apply(this, arguments);
}
function plain(fmt) {
@ -116,7 +116,7 @@ function debug(name) {
fmt = new Date().toUTCString()
+ ' ' + name + ' ' + fmt;
console.error.apply(this, arguments);
console.log.apply(this, arguments);
}
colored.enabled = plain.enabled = true;