Skip to content

Commit ab5083f

Browse files
abenhamdineTooTallNate
authored andcommittedNov 8, 2017
Document enable() (#517)
Document enable, and help to avoid pitfall of #425
1 parent 7116906 commit ab5083f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎README.md

+35
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,41 @@ error('now goes to stdout via console.info');
248248
log('still goes to stdout, but via console.info now');
249249
```
250250

251+
## Set dynamically
252+
253+
You can also enable debug dynamically by calling the `enable()` method :
254+
255+
```js
256+
let debug = require('debug');
257+
258+
console.log(1, debug.enabled('test'));
259+
260+
debug.enable('test');
261+
console.log(2, debug.enabled('test'));
262+
263+
debug.disable();
264+
console.log(3, debug.enabled('test'));
265+
266+
```
267+
268+
print :
269+
```
270+
1 false
271+
2 true
272+
3 false
273+
```
274+
275+
Usage :
276+
`enable(namespaces)`
277+
`namespaces` can include modes separated by a colon and wildcards.
278+
279+
Note that calling `enable()` completely overrides previously set DEBUG variable :
280+
281+
```
282+
$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))'
283+
=> false
284+
```
285+
251286
## Checking whether a debug target is enabled
252287

253288
After you've created a debug instance, you can determine whether or not it is

0 commit comments

Comments
 (0)
Please sign in to comment.