From d844a6eef793985de46b9821dd803b935c4354e2 Mon Sep 17 00:00:00 2001 From: Arnaud Benhamdine Date: Fri, 13 Oct 2017 10:02:50 +0200 Subject: [PATCH] Document enable() Document enable, and help to avoid pitfall of https://github.com/visionmedia/debug/issues/425 Don't hesitate to reword if need be. --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 8e754d17..8a3b70bf 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,41 @@ error('now goes to stdout via console.info'); log('still goes to stdout, but via console.info now'); ``` +## Set dynamically + +You can also enable debug dynamically by calling the `enable()` method : + +```js +let debug = require('debug'); + +console.log(1, debug.enabled('test')); + +debug.enable('test'); +console.log(2, debug.enabled('test')); + +debug.disable(); +console.log(3, debug.enabled('test')); + +``` + +print : +``` +1 false +2 true +3 false +``` + +Usage : +`enable(namespaces)` +`namespaces` can include modes separated by a colon and wildcards. + +Note that calling `enable()` completely overrides previously set DEBUG variable : + +``` +$ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))' +=> false +``` + ## Checking whether a debug target is enabled After you've created a debug instance, you can determine whether or not it is