Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 873: doc update for global output streams #942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,28 +249,31 @@ In Chromium-based web browsers (e.g. Brave, Chrome, and Electron), the JavaScrip

By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:

Example [_stdout.js_](./examples/node/stdout.js):

```js
var debug = require('debug');
var error = debug('app:error');

// by default stderr is used
error('goes to stderr!');

var log = debug('app:log');
// set this namespace to log via console.log
log.log = console.log.bind(console); // don't forget to bind to console!
log('goes to stdout');
var log1 = debug('app:log1');
var log2 = debug('app:log2');

// set this namespace to log1 via console.log
log1.log = console.log.bind(console); // don't forget to bind to console!
log1('goes to stdout');
error('still goes to stderr!');

// set all output to go via console.info
// overrides all per-namespace log settings
// set default output to go via console.info
// overrides all unconfigured per-namespace log settings
debug.log = console.info.bind(console);
error('now goes to stdout via console.info');
log('still goes to stdout, but via console.info now');
log1('still goes to stdout');
log2('still goes to stdout, but via console.info now');
```

Note: overriding the `debug` instance log will not apply to a namespace that already has a defined output stream.

## Extend
You can simply extend debugger
```js
Expand Down