From a45d4a0239f071634804dd7901dd33b0d0d407c9 Mon Sep 17 00:00:00 2001 From: Tim Ruffles Date: Thu, 15 Jun 2017 22:39:48 +0100 Subject: [PATCH 01/41] document .enabled flag (#465) Was added in #15, should be documented (e.g #423) --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f67be6b3..15f2a17e 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,18 @@ error('now goes to stdout via console.info'); log('still goes to stdout, but via console.info now'); ``` +## Checking whether a debug target is enabled + +Afer you've created a debug instance, you can check whether it is enabled by its `.enabled` property: + +```javascript +const debug = require('debug')('http'); + +if(debug.enabled) { + // ... +} +``` + ## Authors From 659ac0252cd3bba115b02a4545b752ac9dcc3064 Mon Sep 17 00:00:00 2001 From: "Mattias Kindborg @FantasticFiasco" Date: Fri, 4 Aug 2017 20:51:36 +0200 Subject: [PATCH 02/41] docs(readme): fix typo (#473) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15f2a17e..441cbecd 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ log('still goes to stdout, but via console.info now'); ## Checking whether a debug target is enabled -Afer you've created a debug instance, you can check whether it is enabled by its `.enabled` property: +After you've created a debug instance, you can check whether it is enabled by its `.enabled` property: ```javascript const debug = require('debug')('http'); From ff432e76e98f4224917af75a2d2dd1057edff3ac Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 27 Dec 2016 16:25:36 -0800 Subject: [PATCH 03/41] Remove DEBUG_FD (#406) * remove DEBUG_FD Now simply uses `process.stderr`. Breaking API change, for the v3 branch. Previously used internal and undocumented Node.js APIs to support this underly used API. Fixes #280 Closes #386 * remove DEBUG_FD from readme --- src/node.js | 91 ++--------------------------------------------------- 1 file changed, 3 insertions(+), 88 deletions(-) diff --git a/src/node.js b/src/node.js index af612976..f4119f47 100644 --- a/src/node.js +++ b/src/node.js @@ -51,23 +51,6 @@ exports.inspectOpts = Object.keys(process.env).filter(function (key) { return obj; }, {}); -/** - * The file descriptor to write the `debug()` calls to. - * Set the `DEBUG_FD` env variable to override with another value. i.e.: - * - * $ DEBUG_FD=3 node script.js 3>debug.log - */ - -var fd = parseInt(process.env.DEBUG_FD, 10) || 2; - -if (1 !== fd && 2 !== fd) { - util.deprecate(function(){}, 'except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)')() -} - -var stream = 1 === fd ? process.stdout : - 2 === fd ? process.stderr : - createWritableStdioStream(fd); - /** * Is stdout a TTY? Colored output is enabled when `true`. */ @@ -75,7 +58,7 @@ var stream = 1 === fd ? process.stdout : function useColors() { return 'colors' in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) - : tty.isatty(fd); + : tty.isatty(process.stderr.fd); } /** @@ -120,11 +103,11 @@ function formatArgs(args) { } /** - * Invokes `util.format()` with the specified arguments and writes to `stream`. + * Invokes `util.format()` with the specified arguments and writes to stderr. */ function log() { - return stream.write(util.format.apply(util, arguments) + '\n'); + return process.stderr.write(util.format.apply(util, arguments) + '\n'); } /** @@ -155,74 +138,6 @@ function load() { return process.env.DEBUG; } -/** - * Copied from `node/src/node.js`. - * - * XXX: It's lame that node doesn't expose this API out-of-the-box. It also - * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame. - */ - -function createWritableStdioStream (fd) { - var stream; - var tty_wrap = process.binding('tty_wrap'); - - // Note stream._type is used for test-module-load-list.js - - switch (tty_wrap.guessHandleType(fd)) { - case 'TTY': - stream = new tty.WriteStream(fd); - stream._type = 'tty'; - - // Hack to have stream not keep the event loop alive. - // See https://github.com/joyent/node/issues/1726 - if (stream._handle && stream._handle.unref) { - stream._handle.unref(); - } - break; - - case 'FILE': - var fs = require('fs'); - stream = new fs.SyncWriteStream(fd, { autoClose: false }); - stream._type = 'fs'; - break; - - case 'PIPE': - case 'TCP': - var net = require('net'); - stream = new net.Socket({ - fd: fd, - readable: false, - writable: true - }); - - // FIXME Should probably have an option in net.Socket to create a - // stream from an existing fd which is writable only. But for now - // we'll just add this hack and set the `readable` member to false. - // Test: ./node test/fixtures/echo.js < /etc/passwd - stream.readable = false; - stream.read = null; - stream._type = 'pipe'; - - // FIXME Hack to have stream not keep the event loop alive. - // See https://github.com/joyent/node/issues/1726 - if (stream._handle && stream._handle.unref) { - stream._handle.unref(); - } - break; - - default: - // Probably an error on in uv_guess_handle() - throw new Error('Implement me. Unknown stream file type!'); - } - - // For supporting legacy API we put the FD here. - stream.fd = fd; - - stream._isStdio = true; - - return stream; -} - /** * Init logic for `debug` instances. * From 9d7c997992416bc9b358aaa5aa9e9396bab54baa Mon Sep 17 00:00:00 2001 From: George Joseph Date: Wed, 4 Jan 2017 12:59:29 -0700 Subject: [PATCH 04/41] Make millisecond timer namespace specific and allow 'always enabled' output (#408) * Make millisecond timer namespace specific When debugging node apps, I find it much more useful for the millisecond timer to be relative to last message from the same namespace instead of any message. This is especially true when I'm debugging across multiple libraries or multiple levels in the same module and I'm interested in seeing all the messages but also need to compare times from specific levels. * Enable 'always enabled' output Having to deal with 2 different logging mechanisms, one for debugging and one for normal output, can be a nuisance. It would be much easier to always use the same facility and semantics for both. This patch allows an 'always enabled' namespace to be specified by appending a single '*' to the namespace name. var alwaysOn = require('debug')('normal:messages*'); alwaysOn('This will always display regardless of DEBUG'); --- README.md | 2 +- src/debug.js | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 441cbecd..3748db94 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Then, run the program to be debugged as usual. ## Conventions - If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". + If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output. ## Wildcards diff --git a/src/debug.js b/src/debug.js index 6a5e3fc9..ee31a398 100644 --- a/src/debug.js +++ b/src/debug.js @@ -28,12 +28,6 @@ exports.skips = []; exports.formatters = {}; -/** - * Previous log timestamp. - */ - -var prevTime; - /** * Select a color. * @param {String} namespace @@ -62,6 +56,8 @@ function selectColor(namespace) { function createDebug(namespace) { + var prevTime; + function debug() { // disabled? if (!debug.enabled) return; @@ -174,6 +170,9 @@ function disable() { */ function enabled(name) { + if (name[name.length - 1] === '*') { + return true; + } var i, len; for (i = 0, len = exports.skips.length; i < len; i++) { if (exports.skips[i].test(name)) { From bf88540737e3908eeac253ffd2bbde0b46d5b56d Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Wed, 12 Apr 2017 13:25:31 -0700 Subject: [PATCH 05/41] `enabled()` updates existing debug instances, add `destroy()` function (#440) * dynamically updatable instances * add a `destroy()` function to debug instances So that "dynamically created instances" can clean up after themselves --- src/debug.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/debug.js b/src/debug.js index ee31a398..ed2956d6 100644 --- a/src/debug.js +++ b/src/debug.js @@ -13,6 +13,11 @@ exports.enable = enable; exports.enabled = enabled; exports.humanize = require('ms'); +/** + * Active `debug` instances. + */ +exports.instances = []; + /** * The currently active debug mode names, and names to skip. */ @@ -114,15 +119,23 @@ function createDebug(namespace) { debug.enabled = exports.enabled(namespace); debug.useColors = exports.useColors(); debug.color = selectColor(namespace); + debug.destroy = destroy; // env-specific initialization logic for debug instances if ('function' === typeof exports.init) { exports.init(debug); } + exports.instances.push(debug); + return debug; } +function destroy () { + const index = exports.instances.indexOf(this) + exports.instances.splice(index, 1) +} + /** * Enables a debug mode by namespaces. This can include modes * separated by a colon and wildcards. @@ -149,6 +162,11 @@ function enable(namespaces) { exports.names.push(new RegExp('^' + namespaces + '$')); } } + + for (var i = 0; i < exports.instances.length; i++) { + var instance = exports.instances[i]; + instance.enabled = exports.enabled(instance.namespace); + } } /** From d5854f4eb6868c3d424091648ab92a3575b0b55e Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 7 Aug 2017 21:51:55 -0700 Subject: [PATCH 06/41] support 256 colors Closes #481. --- src/node.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index f4119f47..bc3d8d0d 100644 --- a/src/node.js +++ b/src/node.js @@ -25,6 +25,23 @@ exports.useColors = useColors; exports.colors = [6, 2, 3, 4, 5, 1]; +try { + var supportsColor = require('supports-color'); + if (supportsColor && supportsColor.level >= 2) { + exports.colors = [ + 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 92, 93, 98, 99, 112, 113, 118, 119, 128, 129, + 134, 135, 148, 149, 154, 155, 160, 161, 162, 163, 164, 165, 166, 167, + 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 190, 191, 196, 197, + 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, + 220, 221, 226, 227 + ]; + } +} catch (err) { + // swallow - we only care if `supports-color` is available; it doesn't have to be. +} + /** * Build up the default `inspectOpts` object from the environment variables. * @@ -92,10 +109,11 @@ function formatArgs(args) { if (useColors) { var c = this.color; - var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m'; + var colorCode = '\u001b[3' + (c < 8 ? c : '8;5;' + c); + var prefix = ' ' + colorCode + ';1m' + name + ' ' + '\u001b[0m'; args[0] = prefix + args[0].split('\n').join('\n' + prefix); - args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); + args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); } else { args[0] = new Date().toUTCString() + ' ' + name + ' ' + args[0]; From 39eb2770a2ae2e9cd51356d2f6324616484274c3 Mon Sep 17 00:00:00 2001 From: "antoine.leveugle" Date: Sun, 29 Jan 2017 17:10:42 +0100 Subject: [PATCH 07/41] Use Date#toISOString() instead to Date#toUTCString() when output is not a TTY Easier to parse programatically and contains milliseconds. Closes #418. --- README.md | 2 +- src/node.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3748db94..bca8417e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Then, run the program to be debugged as usual. ![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) - When stdout is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below: + When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below: ![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) diff --git a/src/node.js b/src/node.js index bc3d8d0d..ae556fc0 100644 --- a/src/node.js +++ b/src/node.js @@ -115,7 +115,7 @@ function formatArgs(args) { args[0] = prefix + args[0].split('\n').join('\n' + prefix); args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); } else { - args[0] = new Date().toUTCString() + args[0] = new Date().toISOString() + ' ' + name + ' ' + args[0]; } } From 826fd94639efeaa3c5701b50d335caead084a5d6 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 11:46:13 -0700 Subject: [PATCH 08/41] update "browserify" to v14.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df863517..bad6f09b 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "ms": "2.0.0" }, "devDependencies": { - "browserify": "9.0.3", + "browserify": "14.4.0", "chai": "^3.5.0", "concurrently": "^3.1.0", "coveralls": "^2.11.15", From cefbd07bd8168a0352f858129562fb9d480b76b2 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 11:54:27 -0700 Subject: [PATCH 09/41] update `make lint` --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 584da8bf..304b6a5e 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ node_modules: package.json @touch node_modules lint: .FORCE - eslint browser.js debug.js index.js node.js + eslint *.js src/*.js test-node: .FORCE istanbul cover node_modules/mocha/bin/_mocha -- test/**.js From 65192b755dcbaef9e958c28a70833e5bd6758264 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Tue, 8 Aug 2017 11:59:22 -0700 Subject: [PATCH 10/41] use contrast-bounded colors --- src/node.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/node.js b/src/node.js index ae556fc0..b85ec7e3 100644 --- a/src/node.js +++ b/src/node.js @@ -23,19 +23,17 @@ exports.useColors = useColors; * Colors. */ -exports.colors = [6, 2, 3, 4, 5, 1]; +exports.colors = [ 6, 2, 3, 4, 5, 1 ]; try { var supportsColor = require('supports-color'); if (supportsColor && supportsColor.level >= 2) { exports.colors = [ - 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 92, 93, 98, 99, 112, 113, 118, 119, 128, 129, - 134, 135, 148, 149, 154, 155, 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 190, 191, 196, 197, - 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, - 220, 221, 226, 227 + 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, + 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, + 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, + 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 208, 209, 214, 215, 220, 221 ]; } } catch (err) { From 5ed41f6d92b639cdaa1b2e93fc4071886b5a82db Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 11:59:56 -0700 Subject: [PATCH 11/41] add Web Browser 256 colors Like #481, but for the web browser. --- src/browser.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/browser.js b/src/browser.js index 71069249..879aaa79 100644 --- a/src/browser.js +++ b/src/browser.js @@ -20,12 +20,17 @@ exports.storage = 'undefined' != typeof chrome */ exports.colors = [ - 'lightseagreen', - 'forestgreen', - 'goldenrod', - 'dodgerblue', - 'darkorchid', - 'crimson' + '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', + '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', + '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', + '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', + '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', + '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', + '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', + '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', + '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', + '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', + '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33' ]; /** From 02eb3c607e38d709b79701a0d0140da77b006bdf Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:01:01 -0700 Subject: [PATCH 12/41] fix lint --- src/debug.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/debug.js b/src/debug.js index ed2956d6..7c49039c 100644 --- a/src/debug.js +++ b/src/debug.js @@ -150,10 +150,11 @@ function enable(namespaces) { exports.names = []; exports.skips = []; + var i; var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); var len = split.length; - for (var i = 0; i < len; i++) { + for (i = 0; i < len; i++) { if (!split[i]) continue; // ignore empty strings namespaces = split[i].replace(/\*/g, '.*?'); if (namespaces[0] === '-') { @@ -163,7 +164,7 @@ function enable(namespaces) { } } - for (var i = 0; i < exports.instances.length; i++) { + for (i = 0; i < exports.instances.length; i++) { var instance = exports.instances[i]; instance.enabled = exports.enabled(instance.namespace); } From 25e07c78fc5eec5a593ebf51b2a1ed3605897e0e Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:01:09 -0700 Subject: [PATCH 13/41] don't call splice() when indexOf() returns -1 --- src/debug.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/debug.js b/src/debug.js index 7c49039c..77e6384a 100644 --- a/src/debug.js +++ b/src/debug.js @@ -132,8 +132,13 @@ function createDebug(namespace) { } function destroy () { - const index = exports.instances.indexOf(this) - exports.instances.splice(index, 1) + var index = exports.instances.indexOf(this); + if (index !== -1) { + exports.instances.splice(index, 1); + return true; + } else { + return false; + } } /** From 87880f6ae1f48b12d9f3346bce564a66cba6b93e Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:30:57 -0700 Subject: [PATCH 14/41] separate Node.js and web browser examples --- example/browser.html | 26 -------------------------- example/wildcards.js | 10 ---------- examples/browser/colors.html | 26 ++++++++++++++++++++++++++ {example => examples/node}/app.js | 4 ++-- examples/node/colors.js | 7 +++++++ {example => examples/node}/stdout.js | 2 +- examples/node/wildcards.js | 10 ++++++++++ {example => examples/node}/worker.js | 4 ++-- 8 files changed, 48 insertions(+), 41 deletions(-) delete mode 100644 example/browser.html delete mode 100644 example/wildcards.js create mode 100644 examples/browser/colors.html rename {example => examples/node}/app.js (82%) create mode 100644 examples/node/colors.js rename {example => examples/node}/stdout.js (94%) create mode 100644 examples/node/wildcards.js rename {example => examples/node}/worker.js (84%) diff --git a/example/browser.html b/example/browser.html deleted file mode 100644 index 00904189..00000000 --- a/example/browser.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - debug() - - - - - - - - diff --git a/example/wildcards.js b/example/wildcards.js deleted file mode 100644 index 1fdac20a..00000000 --- a/example/wildcards.js +++ /dev/null @@ -1,10 +0,0 @@ - -var debug = { - foo: require('../')('test:foo'), - bar: require('../')('test:bar'), - baz: require('../')('test:baz') -}; - -debug.foo('foo') -debug.bar('bar') -debug.baz('baz') \ No newline at end of file diff --git a/examples/browser/colors.html b/examples/browser/colors.html new file mode 100644 index 00000000..5d023bb2 --- /dev/null +++ b/examples/browser/colors.html @@ -0,0 +1,26 @@ + + + + debug() + + + + + + + Open your + Web Inspector + to see the debug output + + diff --git a/example/app.js b/examples/node/app.js similarity index 82% rename from example/app.js rename to examples/node/app.js index 05374d98..011b63ad 100644 --- a/example/app.js +++ b/examples/node/app.js @@ -1,5 +1,5 @@ -var debug = require('../')('http') +var debug = require('../../')('http') , http = require('http') , name = 'My App'; @@ -16,4 +16,4 @@ http.createServer(function(req, res){ // fake worker of some kind -require('./worker'); \ No newline at end of file +require('./worker'); diff --git a/examples/node/colors.js b/examples/node/colors.js new file mode 100644 index 00000000..bcc52d94 --- /dev/null +++ b/examples/node/colors.js @@ -0,0 +1,7 @@ +var debug = require('../../') + +debug.enable('*') + +for (var i=0; i < debug.colors.length; i++) { + debug('example:' + i)('The color is %o', debug.colors[i]) +} diff --git a/example/stdout.js b/examples/node/stdout.js similarity index 94% rename from example/stdout.js rename to examples/node/stdout.js index e15322da..c999c4c0 100644 --- a/example/stdout.js +++ b/examples/node/stdout.js @@ -1,4 +1,4 @@ -var debug = require('../'); +var debug = require('../../'); var error = debug('app:error'); // by default stderr is used diff --git a/examples/node/wildcards.js b/examples/node/wildcards.js new file mode 100644 index 00000000..ca99aeff --- /dev/null +++ b/examples/node/wildcards.js @@ -0,0 +1,10 @@ + +var debug = { + foo: require('../../')('test:foo'), + bar: require('../../')('test:bar'), + baz: require('../../')('test:baz') +}; + +debug.foo('foo') +debug.bar('bar') +debug.baz('baz') diff --git a/example/worker.js b/examples/node/worker.js similarity index 84% rename from example/worker.js rename to examples/node/worker.js index 22225f60..07e3bc59 100644 --- a/example/worker.js +++ b/examples/node/worker.js @@ -4,8 +4,8 @@ // DEBUG=worker:a node example/worker // DEBUG=worker:b node example/worker -var a = require('../')('worker:a') - , b = require('../')('worker:b'); +var a = require('../../')('worker:a') + , b = require('../../')('worker:b'); function work() { a('doing lots of uninteresting work'); From ce1a236d93a971dc74930972a03d4d0fe409effd Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:31:21 -0700 Subject: [PATCH 15/41] Makefile tweaks Re-introduce `make browser` to make a standalone build of `debug.js` for the web browser. --- Makefile | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 304b6a5e..b86958ab 100644 --- a/Makefile +++ b/Makefile @@ -15,31 +15,31 @@ YARN ?= $(shell which yarn) PKG ?= $(if $(YARN),$(YARN),$(NODE) $(shell which npm)) BROWSERIFY ?= $(NODE) $(BIN)/browserify -.FORCE: - install: node_modules +browser: dist/debug.js + node_modules: package.json @NODE_ENV= $(PKG) install @touch node_modules -lint: .FORCE - eslint *.js src/*.js - -test-node: .FORCE - istanbul cover node_modules/mocha/bin/_mocha -- test/**.js - -test-browser: .FORCE - mkdir -p dist - +dist/debug.js: src/*.js node_modules + @mkdir -p dist @$(BROWSERIFY) \ --standalone debug \ . > dist/debug.js +lint: + eslint *.js src/*.js + +test-node: + istanbul cover node_modules/mocha/bin/_mocha -- test/**.js + +test-browser: + $(MAKE) browser karma start --single-run - rimraf dist -test: .FORCE +test: concurrently \ "make test-node" \ "make test-browser" @@ -47,4 +47,7 @@ test: .FORCE coveralls: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js +clean: + rimraf dist + .PHONY: all install clean distclean From dfbac9c30f7f3af8c44802197d47450bcbd94952 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:54:19 -0700 Subject: [PATCH 16/41] readme refactor --- README.md | 118 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index bca8417e..861f2993 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ [![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors) + - -A tiny node.js debugging utility modelled after node core's debugging technique. +A tiny JavaScript debugging utility modelled after Node.js core's debugging +technique. Works in Node.js and web browsers. **Discussion around the V3 API is under way [here](https://github.com/visionmedia/debug/issues/370)** @@ -27,7 +28,7 @@ var debug = require('debug')('http') // fake app -debug('booting %s', name); +debug('booting %o', name); http.createServer(function(req, res){ debug(req.method + ' ' + req.url); @@ -51,52 +52,62 @@ setInterval(function(){ }, 1000); ``` - The __DEBUG__ environment variable is then used to enable these based on space or comma-delimited names. Here are some examples: +The `DEBUG` environment variable is then used to enable these based on space or +comma-delimited names. - ![debug http and worker](http://f.cl.ly/items/18471z1H402O24072r1J/Screenshot.png) +Here are some examples: - ![debug worker](http://f.cl.ly/items/1X413v1a3M0d3C2c1E0i/Screenshot.png) +screen shot 2017-08-08 at 12 53 04 pm +screen shot 2017-08-08 at 12 53 38 pm +screen shot 2017-08-08 at 12 53 25 pm #### Windows note - On Windows the environment variable is set using the `set` command. +On Windows the environment variable is set using the `set` command. - ```cmd - set DEBUG=*,-not_this - ``` +```cmd +set DEBUG=*,-not_this +``` - Note that PowerShell uses different syntax to set environment variables. +Note that PowerShell uses different syntax to set environment variables. - ```cmd - $env:DEBUG = "*,-not_this" - ``` +```cmd +$env:DEBUG = "*,-not_this" +``` Then, run the program to be debugged as usual. ## Millisecond diff - When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. +When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. - ![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) +![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) - When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below: +When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below: + +![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) - ![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) ## Conventions - If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output. +If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output. ## Wildcards - The `*` character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`. +The `*` character may be used as a wildcard. Suppose for example your library has +debuggers named "connect:bodyParser", "connect:compress", "connect:session", +instead of listing all three with +`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do +`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`. - You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=*,-connect:*` would include all debuggers except those starting with "connect:". +You can also exclude specific debuggers by prefixing them with a "-" character. +For example, `DEBUG=*,-connect:*` would include all debuggers except those +starting with "connect:". ## Environment Variables - When running through Node.js, you can set a few environment variables that will - change the behavior of the debug logging: +When running through Node.js, you can set a few environment variables that will +change the behavior of the debug logging: | Name | Purpose | |-----------|-------------------------------------------------| @@ -106,16 +117,16 @@ Then, run the program to be debugged as usual. | `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. | - __Note:__ The environment variables beginning with `DEBUG_` end up being - converted into an Options object that gets used with `%o`/`%O` formatters. - See the Node.js documentation for - [`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options) - for the complete list. +__Note:__ The environment variables beginning with `DEBUG_` end up being +converted into an Options object that gets used with `%o`/`%O` formatters. +See the Node.js documentation for +[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options) +for the complete list. ## Formatters - - Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. Below are the officially supported formatters: +Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. +Below are the officially supported formatters: | Formatter | Representation | |-----------|----------------| @@ -126,9 +137,12 @@ Then, run the program to be debugged as usual. | `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | | `%%` | Single percent sign ('%'). This does not consume an argument. | + ### Custom formatters - You can add custom formatters by extending the `debug.formatters` object. For example, if you wanted to add support for rendering a Buffer as hex with `%h`, you could do something like: +You can add custom formatters by extending the `debug.formatters` object. +For example, if you wanted to add support for rendering a Buffer as hex with +`%h`, you could do something like: ```js const createDebug = require('debug') @@ -142,14 +156,16 @@ debug('this is hex: %h', new Buffer('hello world')) // foo this is hex: 68656c6c6f20776f726c6421 +0ms ``` -## Browser support - You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify), - or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest), - if you don't want to build it yourself. - Debug's enable state is currently persisted by `localStorage`. - Consider the situation shown below where you have `worker:a` and `worker:b`, - and wish to debug both. You can enable this using `localStorage.debug`: +## Browser Support + +You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify), +or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest), +if you don't want to build it yourself. + +Debug's enable state is currently persisted by `localStorage`. +Consider the situation shown below where you have `worker:a` and `worker:b`, +and wish to debug both. You can enable this using `localStorage.debug`: ```js localStorage.debug = 'worker:*' @@ -172,21 +188,21 @@ setInterval(function(){ #### Web Inspector Colors - Colors are also enabled on "Web Inspectors" that understand the `%c` formatting - option. These are WebKit web inspectors, Firefox ([since version - 31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) - and the Firebug plugin for Firefox (any version). +Colors are also enabled on "Web Inspectors" that understand the `%c` formatting +option. These are WebKit web inspectors, Firefox ([since version +31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) +and the Firebug plugin for Firefox (any version). - Colored output looks something like: +Colored output looks something like: - ![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png) +![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png) ## Output streams By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method: -Example _stdout.js_: +Example [_stdout.js_](./examples/node/stdout.js): ```js var debug = require('debug'); @@ -210,16 +226,20 @@ log('still goes to stdout, but via console.info now'); ## Checking whether a debug target is enabled -After you've created a debug instance, you can check whether it is enabled by its `.enabled` property: +After you've created a debug instance, you can determine whether or not it is +enabled by checking the `enabled` property: ```javascript const debug = require('debug')('http'); -if(debug.enabled) { - // ... +if (debug.enabled) { + // do stuff... } ``` +You can also manually toggle this property to force the debug instance to be +enabled or disabled. + ## Authors @@ -302,7 +322,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s (The MIT License) -Copyright (c) 2014-2016 TJ Holowaychuk <tj@vision-media.ca> +Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 31f3343de76cb8687041387a1b811745c6e84473 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 12:56:04 -0700 Subject: [PATCH 17/41] example: use %o formatter --- examples/node/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/node/app.js b/examples/node/app.js index 011b63ad..d4a19914 100644 --- a/examples/node/app.js +++ b/examples/node/app.js @@ -5,7 +5,7 @@ var debug = require('../../')('http') // fake app -debug('booting %s', name); +debug('booting %o', name); http.createServer(function(req, res){ debug(req.method + ' ' + req.url); From 25eb545324912dd2863658d0ba35426c0f617619 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 13:02:54 -0700 Subject: [PATCH 18/41] more readme screenshots replaced --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 861f2993..a09db3a7 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,11 @@ Then, run the program to be debugged as usual. When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. -![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) + When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below: -![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) + ## Conventions @@ -193,9 +193,9 @@ option. These are WebKit web inspectors, Firefox ([since version 31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) and the Firebug plugin for Firefox (any version). -Colored output looks something like: +Colored output looks like: -![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png) + ## Output streams From 8b5c438a222167bd0cc66db046bac073f01b3c01 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 13:10:08 -0700 Subject: [PATCH 19/41] add Namespace Colors section to readme --- README.md | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a09db3a7..46c22a9b 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,31 @@ $env:DEBUG = "*,-not_this" Then, run the program to be debugged as usual. + +## Namespace Colors + +Every debug instance has a color generated for it based on its namespace name. +This helps when visually parsing the debug output to identify which debug instance +a debug line belongs to. + +#### Node.js + +In Node.js, colors are enabled when stderr is a TTY. You also _should_ install +the [`supports-color`](https://npmjs.org/supports-color) module alongside debug, +otherwise debug will only use a small handful of basic colors. + + + +#### Web Browser + +Colors are also enabled on "Web Inspectors" that understand the `%c` formatting +option. These are WebKit web inspectors, Firefox ([since version +31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) +and the Firebug plugin for Firefox (any version). + + + + ## Millisecond diff When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. @@ -186,17 +211,6 @@ setInterval(function(){ }, 1200); ``` -#### Web Inspector Colors - -Colors are also enabled on "Web Inspectors" that understand the `%c` formatting -option. These are WebKit web inspectors, Firefox ([since version -31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) -and the Firebug plugin for Firefox (any version). - -Colored output looks like: - - - ## Output streams From 87e7399fd7e6c4196082bcbfd02bedf95d1b9c76 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 13:12:42 -0700 Subject: [PATCH 20/41] readme++ --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 46c22a9b..a2b122e9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ $ npm install debug `debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole. -Example _app.js_: +Example [_app.js_](./examples/node/app.js): ```js var debug = require('debug')('http') @@ -42,14 +42,25 @@ http.createServer(function(req, res){ require('./worker'); ``` -Example _worker.js_: +Example [_worker.js_](./examples/node/worker.js): ```js -var debug = require('debug')('worker'); +var a = require('debug')('worker:a') + , b = require('debug')('worker:b'); -setInterval(function(){ - debug('doing some work'); -}, 1000); +function work() { + a('doing lots of uninteresting work'); + setTimeout(work, Math.random() * 1000); +} + +work(); + +function workb() { + b('doing some work'); + setTimeout(workb, Math.random() * 2000); +} + +workb(); ``` The `DEBUG` environment variable is then used to enable these based on space or From 402c8567ee3e01e36464ba9591ac436de6fbf0a9 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 13:30:21 -0700 Subject: [PATCH 21/41] fix lint --- .eslintrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.eslintrc b/.eslintrc index 8a37ae2c..146371ed 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,6 +3,9 @@ "browser": true, "node": true }, + "globals": { + "chrome": true + }, "rules": { "no-console": 0, "no-empty": [1, { "allowEmptyCatch": true }] From d73c4aec194f98a3075adf530b020d4b3098c6cc Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:17:03 -0700 Subject: [PATCH 22/41] fix `make test` --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b86958ab..5d400023 100644 --- a/Makefile +++ b/Makefile @@ -50,4 +50,4 @@ coveralls: clean: rimraf dist -.PHONY: all install clean distclean +.PHONY: browser install clean coveralls lint test test-node test-browser From f178d861df18abacac6e9e4607c7306a1147bf3d Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:26:59 -0700 Subject: [PATCH 23/41] attempt to separate the Node and Browser tests in Travis --- .travis.yml | 13 ++++++++++--- Makefile | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c6090c3..1a5bde09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,21 @@ +sudo: false language: node_js + node_js: - - "6" - - "5" - "4" + - "6" + - "8" install: - - make node_modules + - make install script: - make lint - make test - make coveralls + +matrix: + include: + - node_js: '8' + env: BROWSER=1 diff --git a/Makefile b/Makefile index 5d400023..f4f89d02 100644 --- a/Makefile +++ b/Makefile @@ -30,24 +30,29 @@ dist/debug.js: src/*.js node_modules . > dist/debug.js lint: - eslint *.js src/*.js + @eslint *.js src/*.js test-node: - istanbul cover node_modules/mocha/bin/_mocha -- test/**.js + @istanbul cover node_modules/mocha/bin/_mocha -- test/**.js + @cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js test-browser: - $(MAKE) browser - karma start --single-run + @$(MAKE) browser + @karma start --single-run -test: - concurrently \ +test-all: + @concurrently \ "make test-node" \ "make test-browser" -coveralls: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js +test: + @if [ "x$(BROWSER_NAME)" = "x" ]; then \ + $(MAKE) test-node; \ + else \ + $(MAKE) test-browser; \ + fi clean: - rimraf dist + rimraf dist coverage -.PHONY: browser install clean coveralls lint test test-node test-browser +.PHONY: browser install clean lint test test-all test-node test-browser From f6f621327796a92d75362e48dff2a1f51299a9ba Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:30:26 -0700 Subject: [PATCH 24/41] remove `make coveralls` from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1a5bde09..a7643003 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ install: script: - make lint - make test - - make coveralls matrix: include: From 67529535431ea0c7368131683e7454266884e2fc Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:34:35 -0700 Subject: [PATCH 25/41] =?UTF-8?q?fix=20browser=20test=20=F0=9F=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f4f89d02..3ddd1360 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ test-all: "make test-browser" test: - @if [ "x$(BROWSER_NAME)" = "x" ]; then \ + @if [ "x$(BROWSER)" = "x" ]; then \ $(MAKE) test-node; \ else \ $(MAKE) test-browser; \ From d2dd80aeaf1b037f0b3be21838c4594bbedc4a9c Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:49:27 -0700 Subject: [PATCH 26/41] component: update "ms" to v2.0.0 --- component.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/component.json b/component.json index 94cd36d8..d1f6e22b 100644 --- a/component.json +++ b/component.json @@ -14,6 +14,6 @@ "src/debug.js" ], "dependencies": { - "rauchg/ms.js": "0.7.1" + "rauchg/ms.js": "2.0.0" } } From 52b894cd798f492ead1866fca4d76a649f0e62c6 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 14:55:46 -0700 Subject: [PATCH 27/41] Release 3.0.0 --- CHANGELOG.md | 16 ++++++++++++++++ component.json | 2 +- package.json | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1a270cd..404d5bef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,20 @@ +3.0.0 / 2017-08-08 +================== + + * Breaking: Remove DEBUG_FD (#406) + * Breaking: Use `Date#toISOString()` instead to `Date#toUTCString()` when output is not a TTY (#418) + * Breaking: Make millisecond timer namespace specific and allow 'always enabled' output (#408) + * Addition: document `enabled` flag (#465) + * Addition: add 256 colors mode (#481) + * Addition: `enabled()` updates existing debug instances, add `destroy()` function (#440) + * Update: component: update "ms" to v2.0.0 + * Update: separate the Node and Browser tests in Travis-CI + * Update: refactor Readme, fixed documentation, added "Namespace Colors" section, redid screenshots + * Update: separate Node.js and web browser examples for organization + * Update: update "browserify" to v14.4.0 + * Fix: fix Readme typo (#473) + 2.6.8 / 2017-05-18 ================== diff --git a/component.json b/component.json index d1f6e22b..531e0123 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "debug", "repo": "visionmedia/debug", "description": "small debugging utility", - "version": "2.6.8", + "version": "3.0.0", "keywords": [ "debug", "log", diff --git a/package.json b/package.json index bad6f09b..869b045d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "2.6.8", + "version": "3.0.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From 13e1d068e9265b2c9a160ba242a6be200b9811f0 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 8 Aug 2017 15:23:50 -0700 Subject: [PATCH 28/41] remove v3 discussion note for now --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a2b122e9..1f3b08e1 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers. -**Discussion around the V3 API is under way [here](https://github.com/visionmedia/debug/issues/370)** - ## Installation ```bash From b3ea123cc45828af926efbf5e5a4c63bd11b7aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Thu, 24 Aug 2017 21:40:18 +0200 Subject: [PATCH 29/41] Disable colors in Edge and Internet Explorer (#489) Fixes #417. --- src/browser.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/browser.js b/src/browser.js index 879aaa79..f5149ff5 100644 --- a/src/browser.js +++ b/src/browser.js @@ -49,6 +49,11 @@ function useColors() { return true; } + // Internet Explorer and Edge do not support colors. + if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { + return false; + } + // is webkit? http://stackoverflow.com/a/16459606/376773 // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || From 3e1849d3aaa1b9a325ad6d054acf695fddb4efe9 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 24 Aug 2017 12:44:17 -0700 Subject: [PATCH 30/41] Release 3.0.1 --- CHANGELOG.md | 5 +++++ component.json | 2 +- package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 404d5bef..a1c0eaf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ +3.0.1 / 2017-08-24 +================== + + * Fix: Disable colors in Edge and Internet Explorer (#489) + 3.0.0 / 2017-08-08 ================== diff --git a/component.json b/component.json index 531e0123..a2e9ad39 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "debug", "repo": "visionmedia/debug", "description": "small debugging utility", - "version": "3.0.0", + "version": "3.0.1", "keywords": [ "debug", "log", diff --git a/package.json b/package.json index 869b045d..1514200b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "3.0.0", + "version": "3.0.1", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git" From daf1a7c8c0f62f5dbc8d48158d6748d0527cc551 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 1 Sep 2017 19:49:50 +0100 Subject: [PATCH 31/41] correct spelling mistake --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1c0eaf5..1cf73043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ 2.6.4 / 2017-04-20 ================== - * Fix: bug that would occure if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo) + * Fix: bug that would occur if process.env.DEBUG is a non-string value. (#444, @LucianBuzzo) * Chore: ignore bower.json in npm installations. (#437, @joaovieira) * Misc: update "ms" to v0.7.3 (@tootallnate) From 7cd9e539ce571fc3314d34d9d1dac3124839dbac Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Wed, 13 Sep 2017 15:39:28 +0200 Subject: [PATCH 32/41] examples: fix colors printout Fixes #502. --- examples/browser/colors.html | 4 +++- examples/node/colors.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/browser/colors.html b/examples/browser/colors.html index 5d023bb2..ce969072 100644 --- a/examples/browser/colors.html +++ b/examples/browser/colors.html @@ -8,13 +8,15 @@ debug.enable('*') for (var i=0; i < debug.colors.length; i++) { - debug('example:' + i)('The color is %o', debug.colors[i]) + const d = debug('example:' + i); + d('The color is %o', d.color); } diff --git a/examples/node/colors.js b/examples/node/colors.js index bcc52d94..c144ee4e 100644 --- a/examples/node/colors.js +++ b/examples/node/colors.js @@ -3,5 +3,6 @@ var debug = require('../../') debug.enable('*') for (var i=0; i < debug.colors.length; i++) { - debug('example:' + i)('The color is %o', debug.colors[i]) + const d = debug('example:' + i); + d('The color is %o', d.color); } From fdfa0f5f6cc7e83fd60b6cf1e7b990cbf6388621 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 15 May 2017 10:48:24 +0200 Subject: [PATCH 33/41] Fix browser detection --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index e12cf4d5..cabcbcda 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ * treat as a browser. */ -if (typeof process !== 'undefined' && process.type === 'renderer') { +if (typeof process === 'undefined' || process.type === 'renderer') { module.exports = require('./browser.js'); } else { module.exports = require('./node.js'); From e7e568a24736486721882282eb21beb31c741647 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 15 Sep 2017 00:25:50 +0200 Subject: [PATCH 34/41] ignore package-lock.json --- .gitignore | 5 ++++- src/{debug.js => common.js} | 0 2 files changed, 4 insertions(+), 1 deletion(-) rename src/{debug.js => common.js} (100%) diff --git a/.gitignore b/.gitignore index f459ae9f..f0cf3a35 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,10 @@ node_modules *.sock build -yarn.lock npm-debug.log dist coverage + +# lockfiles +yarn.lock +package-lock.json diff --git a/src/debug.js b/src/common.js similarity index 100% rename from src/debug.js rename to src/common.js From a0601e5e65ca80ce2f39b1243db332c64c124214 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 15 Sep 2017 02:28:44 +0200 Subject: [PATCH 35/41] fix --- src/{common.js => debug.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{common.js => debug.js} (100%) diff --git a/src/common.js b/src/debug.js similarity index 100% rename from src/common.js rename to src/debug.js From 47747f329fe159e94262318b52b87a48f6c0acd4 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 19 Sep 2017 00:09:21 +0200 Subject: [PATCH 36/41] remove `component.json` The project has been deprected since 2015. We should be encouraging the community to move forward and thus this file should be removed. --- component.json | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 component.json diff --git a/component.json b/component.json deleted file mode 100644 index a2e9ad39..00000000 --- a/component.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "debug", - "repo": "visionmedia/debug", - "description": "small debugging utility", - "version": "3.0.1", - "keywords": [ - "debug", - "log", - "debugger" - ], - "main": "src/browser.js", - "scripts": [ - "src/browser.js", - "src/debug.js" - ], - "dependencies": { - "rauchg/ms.js": "2.0.0" - } -} From c38a0166c266a679c8de012d4eaccec3f944e685 Mon Sep 17 00:00:00 2001 From: Ya Zhuang Date: Fri, 22 Sep 2017 06:26:33 +0800 Subject: [PATCH 37/41] remove ReDoS regexp in %o formatter (#504) --- src/node.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index b85ec7e3..2bc75713 100644 --- a/src/node.js +++ b/src/node.js @@ -83,7 +83,9 @@ function useColors() { exports.formatters.o = function(v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts) - .replace(/\s*\n\s*/g, ' '); + .split('\n').map(function(str) { + return str.trim() + }).join(' '); }; /** From bdb7e0137f84dc8bcfc95daede7c694799d38dbf Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 21 Sep 2017 20:02:06 +0200 Subject: [PATCH 38/41] remove "component" from package.json --- package.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/package.json b/package.json index 1514200b..8777fc3d 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,5 @@ "sinon-chai": "^2.8.0" }, "main": "./src/index.js", - "browser": "./src/browser.js", - "component": { - "scripts": { - "debug/index.js": "browser.js", - "debug/debug.js": "debug.js" - } - } + "browser": "./src/browser.js" } From 56a3853b95990a22079d646601aa01e93eceb1c7 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 22 Sep 2017 15:45:06 +0200 Subject: [PATCH 39/41] Add `DEBUG_HIDE_TTY_DATE` env var (#486) Squashed commit of the following: commit 62589c0a4e1babc5953ea30c7ef80b3867ed0a04 Author: Adrian Mejia Date: Sat Aug 12 15:24:45 2017 -0400 solves merge conflict commit 55e5c5e86812163293779e9bbad1afc252c83230 Author: Adrian Mejia Date: Sat Aug 12 15:21:16 2017 -0400 docs commit e09dec33c15fae136039c7ebd94c23000a35373f Author: Adrian Mejia Date: Sat Aug 12 15:19:10 2017 -0400 cleanup commit 9dd6a2b9ca3b1f0d9852ecf0e64ccc6dacf04fa7 Author: Adrian Mejia Date: Sat Aug 12 15:05:53 2017 -0400 enables DEBUG_HIDE_TTY_DATE --- README.md | 5 +++-- src/node.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1f3b08e1..9157bfc4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # debug -[![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) +[![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors) @@ -149,6 +149,7 @@ change the behavior of the debug logging: | `DEBUG_COLORS`| Whether or not to use colors in the debug output. | | `DEBUG_DEPTH` | Object inspection depth. | | `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. | +| `DEBUG_HIDE_TTY_DATE` | Hide date from debug output on TTY. | __Note:__ The environment variables beginning with `DEBUG_` end up being @@ -269,7 +270,7 @@ enabled or disabled. - TJ Holowaychuk - Nathan Rajlich - Andrew Rhyne - + ## Backers Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/debug#backer)] diff --git a/src/node.js b/src/node.js index 2bc75713..5440d5b0 100644 --- a/src/node.js +++ b/src/node.js @@ -115,8 +115,15 @@ function formatArgs(args) { args[0] = prefix + args[0].split('\n').join('\n' + prefix); args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); } else { - args[0] = new Date().toISOString() - + ' ' + name + ' ' + args[0]; + args[0] = getDate() + name + ' ' + args[0]; + } +} + +function getDate() { + if (exports.inspectOpts.hideTtyDate) { + return ''; + } else { + return new Date().toISOString() + ' '; } } From 2c0df9baf7aefae2ea830e9d5eb2be64f0e71f18 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 26 Sep 2017 21:11:45 +0200 Subject: [PATCH 40/41] rename `DEBUG_HIDE_TTY_DATE` to `DEBUG_HIDE_DATE` The date is actually only printed when output is *NOT* a TTY. Let's just genericize the name instead. --- README.md | 4 ++-- src/node.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9157bfc4..8e754d17 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,10 @@ change the behavior of the debug logging: | Name | Purpose | |-----------|-------------------------------------------------| | `DEBUG` | Enables/disables specific debugging namespaces. | +| `DEBUG_HIDE_DATE` | Hide date from debug output (non-TTY). | | `DEBUG_COLORS`| Whether or not to use colors in the debug output. | -| `DEBUG_DEPTH` | Object inspection depth. | +| `DEBUG_DEPTH` | Object inspection depth. | | `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. | -| `DEBUG_HIDE_TTY_DATE` | Hide date from debug output on TTY. | __Note:__ The environment variables beginning with `DEBUG_` end up being diff --git a/src/node.js b/src/node.js index 5440d5b0..d666fb9c 100644 --- a/src/node.js +++ b/src/node.js @@ -120,7 +120,7 @@ function formatArgs(args) { } function getDate() { - if (exports.inspectOpts.hideTtyDate) { + if (exports.inspectOpts.hideDate) { return ''; } else { return new Date().toISOString() + ' '; From f073e056f33efdd5b311381eb6bca2bc850745bf Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 26 Sep 2017 21:13:38 +0200 Subject: [PATCH 41/41] Release 3.1.0 --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a81736c0..820d21e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ +3.1.0 / 2017-09-26 +================== + + * Add `DEBUG_HIDE_DATE` env var (#486) + * Remove ReDoS regexp in %o formatter (#504) + * Remove "component" from package.json + * Remove `component.json` + * Ignore package-lock.json + * Examples: fix colors printout + * Fix: browser detection + * Fix: spelling mistake (#496, @EdwardBetts) + 3.0.1 / 2017-08-24 ================== diff --git a/package.json b/package.json index 8777fc3d..ada43cfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "debug", - "version": "3.0.1", + "version": "3.1.0", "repository": { "type": "git", "url": "git://github.com/visionmedia/debug.git"