-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node: configurable
util.inspect()
options (#327)
* `formatArgs()` gets passed the args Array directly Rather than working on `arguments`. The Node.js version was for some reason turning the arguments into an Array again so it was happening twice! This should make things faster overall. * whitespace * rename `Readme.md` to `README.md` * refactor the `debug()` constructor a bit Now, debug instances are hot-enabelable. That is, you can toggle the `debug.enabled` boolean on instances to enable or disable an instance. There is still no global version of this functionality. Now all instances get a `useColors` and `colors` property, even disabled ones, in case they get enabled later on. Boot-up time impact should be negligible. * node: allow configurable `util.inspect()` options Via env variables by default. So to get more object depth, you pass the `DEBUG_DEPTH=10` env var. For the `showHidden` option, you set `DEBUG_SHOW_HIDDEN=on`. See the Node.js docs for the complete list of `util.inspect()` options: https://nodejs.org/api/util.html#util_util_inspect_object_options * README: document inspect env variables
- Loading branch information
1 parent
00f3046
commit e58d54b
Showing
4 changed files
with
98 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* Expose `debug()` as the module. | ||
*/ | ||
|
||
exports = module.exports = debug.debug = debug; | ||
exports = module.exports = createDebug.debug = createDebug.default = createDebug; | ||
exports.coerce = coerce; | ||
exports.disable = disable; | ||
exports.enable = enable; | ||
|
@@ -23,7 +23,7 @@ exports.skips = []; | |
/** | ||
* Map of special "%n" handling functions, for the debug "format" argument. | ||
* | ||
* Valid key names are a single, lowercased letter, i.e. "n". | ||
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". | ||
*/ | ||
|
||
exports.formatters = {}; | ||
|
@@ -66,17 +66,13 @@ function selectColor(namespace) { | |
* @api public | ||
*/ | ||
|
||
function debug(namespace) { | ||
function createDebug(namespace) { | ||
|
||
// define the `disabled` version | ||
function disabled() { | ||
} | ||
disabled.enabled = false; | ||
|
||
// define the `enabled` version | ||
function enabled() { | ||
function debug() { | ||
// disabled? | ||
if (!debug.enabled) return; | ||
|
||
var self = enabled; | ||
var self = debug; | ||
|
||
// set `diff` timestamp | ||
var curr = +new Date(); | ||
|
@@ -86,10 +82,7 @@ function debug(namespace) { | |
self.curr = curr; | ||
prevTime = curr; | ||
|
||
// add the `color` if not set | ||
if (null == self.useColors) self.useColors = exports.useColors(); | ||
if (null == self.color && self.useColors) self.color = selectColor(namespace); | ||
|
||
// turn the `arguments` into a proper Array | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < args.length; i++) { | ||
args[i] = arguments[i]; | ||
|
@@ -120,19 +113,24 @@ function debug(namespace) { | |
return match; | ||
}); | ||
|
||
// apply env-specific formatting | ||
args = exports.formatArgs.apply(self, args); | ||
// apply env-specific formatting (colors, etc.) | ||
exports.formatArgs.call(self, args); | ||
|
||
var logFn = enabled.log || exports.log || console.log.bind(console); | ||
logFn.apply(self, args); | ||
} | ||
enabled.enabled = true; | ||
|
||
var fn = exports.enabled(namespace) ? enabled : disabled; | ||
debug.namespace = namespace; | ||
debug.enabled = exports.enabled(namespace); | ||
debug.useColors = exports.useColors(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
debug.color = selectColor(namespae); | ||
This comment has been minimized.
Sorry, something went wrong.
knewter
|
||
|
||
fn.namespace = namespace; | ||
// env-specific initialization logic for debug instances | ||
if ('function' === typeof exports.init) { | ||
exports.init(debug); | ||
} | ||
|
||
return fn; | ||
return debug; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm using webpack-dev-server and here may throw
Uncaught TypeError: exports.useColors is not a function