mirror of
https://github.com/debug-js/debug.git
synced 2026-01-18 16:12:38 +00:00
Exposing enable() method for Node.js to address #27
This commit is contained in:
parent
425ad5b6c7
commit
2e992a0cda
31
lib/debug.js
31
lib/debug.js
@ -17,17 +17,6 @@ module.exports = debug;
|
||||
var names = []
|
||||
, skips = [];
|
||||
|
||||
(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 + '$'));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Colors.
|
||||
*/
|
||||
@ -145,3 +134,23 @@ function coerce(val) {
|
||||
if (val instanceof Error) return val.stack || val.message;
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 || '');
|
||||
Loading…
x
Reference in New Issue
Block a user