Skip to content

Commit 9d7c997

Browse files
gtjosephTooTallNate
authored andcommitted
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');
1 parent ff432e7 commit 9d7c997

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Then, run the program to be debugged as usual.
8585

8686
## Conventions
8787

88-
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".
88+
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.
8989

9090
## Wildcards
9191

src/debug.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ exports.skips = [];
2828

2929
exports.formatters = {};
3030

31-
/**
32-
* Previous log timestamp.
33-
*/
34-
35-
var prevTime;
36-
3731
/**
3832
* Select a color.
3933
* @param {String} namespace
@@ -62,6 +56,8 @@ function selectColor(namespace) {
6256

6357
function createDebug(namespace) {
6458

59+
var prevTime;
60+
6561
function debug() {
6662
// disabled?
6763
if (!debug.enabled) return;
@@ -174,6 +170,9 @@ function disable() {
174170
*/
175171

176172
function enabled(name) {
173+
if (name[name.length - 1] === '*') {
174+
return true;
175+
}
177176
var i, len;
178177
for (i = 0, len = exports.skips.length; i < len; i++) {
179178
if (exports.skips[i].test(name)) {

0 commit comments

Comments
 (0)