Comparing version 1.0.1 to 1.0.2
@@ -10,2 +10,3 @@ | ||
exports.log = log; | ||
exports.formatArgs = formatArgs; | ||
exports.save = save; | ||
@@ -20,8 +21,8 @@ exports.load = load; | ||
exports.colors = [ | ||
'cyan', | ||
'green', | ||
'goldenrod', // "yellow" is just too bright on a white background... | ||
'blue', | ||
'purple', | ||
'red' | ||
'lightseagreen', | ||
'forestgreen', | ||
'goldenrod', | ||
'dodgerblue', | ||
'darkorchid', | ||
'crimson' | ||
]; | ||
@@ -52,5 +53,5 @@ | ||
/** | ||
* Invokes `console.log()` when available. | ||
* No-op when `console.log` is not a "function". | ||
* Colorize log arguments if enabled. | ||
* | ||
@@ -60,3 +61,3 @@ * @api public | ||
function log() { | ||
function formatArgs() { | ||
var args = arguments; | ||
@@ -72,24 +73,34 @@ var useColors = this.useColors; | ||
if (useColors) { | ||
var c = 'color: ' + this.color; | ||
args = [args[0], c, ''].concat(Array.prototype.slice.call(args, 1)); | ||
if (!useColors) return args | ||
// the final "%c" is somewhat tricky, because there could be other | ||
// arguments passed either before or after the %c, so we need to | ||
// figure out the correct index to insert the CSS into | ||
var index = 0; | ||
var lastC = 0; | ||
args[0].replace(/%[a-z%]/g, function(match) { | ||
if ('%%' === match) return; | ||
index++; | ||
if ('%c' === match) { | ||
// we only are interested in the *last* %c | ||
// (the user may have provided their own) | ||
lastC = index; | ||
} | ||
}); | ||
var c = 'color: ' + this.color; | ||
args = [args[0], c, ''].concat(Array.prototype.slice.call(args, 1)); | ||
args.splice(lastC, 0, c); | ||
} | ||
// the final "%c" is somewhat tricky, because there could be other | ||
// arguments passed either before or after the %c, so we need to | ||
// figure out the correct index to insert the CSS into | ||
var index = 0; | ||
var lastC = 0; | ||
args[0].replace(/%[a-z%]/g, function(match) { | ||
if ('%%' === match) return; | ||
index++; | ||
if ('%c' === match) { | ||
// we only are interested in the *last* %c | ||
// (the user may have provided their own) | ||
lastC = index; | ||
} | ||
}); | ||
args.splice(lastC, 0, c); | ||
return args; | ||
} | ||
/** | ||
* Invokes `console.log()` when available. | ||
* No-op when `console.log` is not a "function". | ||
* | ||
* @api public | ||
*/ | ||
function log() { | ||
// This hackery is required for IE8, | ||
@@ -99,3 +110,3 @@ // where the `console.log` function doesn't have 'apply' | ||
&& 'function' == typeof console.log | ||
&& Function.prototype.apply.call(console.log, console, args); | ||
&& Function.prototype.apply.call(console.log, console, arguments); | ||
} | ||
@@ -102,0 +113,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "small debugging utility", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "debug", |
@@ -113,3 +113,7 @@ | ||
exports.log.apply(self, args); | ||
if ('function' === typeof exports.formatArgs) { | ||
args = exports.formatArgs.apply(self, args); | ||
} | ||
var logFn = exports.log || enabled.log || console.log.bind(console); | ||
logFn.apply(self, args); | ||
} | ||
@@ -116,0 +120,0 @@ enabled.enabled = true; |
1.0.2 / 2014-06-10 | ||
================== | ||
* browser: update color palette (#113, @gscottolson) | ||
* common: make console logging function configurable (#108, @timoxley) | ||
* node: fix %o colors on old node <= 0.8.x | ||
* Makefile: find node path using shell/which (#109, @timoxley) | ||
1.0.1 / 2014-06-06 | ||
@@ -37,3 +45,3 @@ ================== | ||
* package: re-add the "component" section | ||
* package: re-add the "component" section | ||
@@ -43,5 +51,5 @@ 0.8.0 / 2014-03-30 | ||
* add `enable()` method for nodejs. Closes #27 | ||
* change from stderr to stdout | ||
* remove unnecessary index.js file | ||
* add `enable()` method for nodejs. Closes #27 | ||
* change from stderr to stdout | ||
* remove unnecessary index.js file | ||
@@ -51,3 +59,3 @@ 0.7.4 / 2013-11-13 | ||
* remove "browserify" key from package.json (fixes something in browserify) | ||
* remove "browserify" key from package.json (fixes something in browserify) | ||
@@ -57,5 +65,5 @@ 0.7.3 / 2013-10-30 | ||
* fix: catch localStorage security error when cookies are blocked (Chrome) | ||
* add debug(err) support. Closes #46 | ||
* add .browser prop to package.json. Closes #42 | ||
* fix: catch localStorage security error when cookies are blocked (Chrome) | ||
* add debug(err) support. Closes #46 | ||
* add .browser prop to package.json. Closes #42 | ||
@@ -62,0 +70,0 @@ 0.7.2 / 2013-02-06 |
28
node.js
@@ -17,2 +17,3 @@ | ||
exports.log = log; | ||
exports.formatArgs = formatArgs; | ||
exports.save = save; | ||
@@ -48,4 +49,15 @@ exports.load = load; | ||
var inspect = (4 === util.inspect.length ? | ||
// node <= 0.8.x | ||
function (v, colors) { | ||
return util.inspect(v, void 0, void 0, colors); | ||
} : | ||
// node > 0.8.x | ||
function (v, colors) { | ||
return util.inspect(v, { colors: colors }); | ||
} | ||
); | ||
exports.formatters.o = function(v) { | ||
return util.inspect(v, { colors: this.useColors }) | ||
return inspect(v, this.useColors) | ||
.replace(/\s*\n\s*/g, ' '); | ||
@@ -55,4 +67,3 @@ }; | ||
/** | ||
* Invokes `console.log()` with the specified arguments, | ||
* after adding ANSI color escape codes if enabled. | ||
* Adds ANSI color escape codes if enabled. | ||
* | ||
@@ -62,3 +73,3 @@ * @api public | ||
function log() { | ||
function formatArgs() { | ||
var args = arguments; | ||
@@ -79,4 +90,11 @@ var useColors = this.useColors; | ||
} | ||
return args; | ||
} | ||
console.log.apply(console, args); | ||
/** | ||
* Invokes `console.log()` with the specified arguments. | ||
*/ | ||
function log() { | ||
return console.log.apply(console, arguments); | ||
} | ||
@@ -83,0 +101,0 @@ |
{ | ||
"name": "debug", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -99,2 +99,28 @@ # debug | ||
### stderr vs stdout | ||
You can set an alternative logging method per-namespace by overriding the `log` method on a per-namespace or globally: | ||
Example _stderr.js_: | ||
```js | ||
var debug = require('../'); | ||
var log = debug('app:log'); | ||
// by default console.log is used | ||
log('goes to stdout!'); | ||
var error = debug('app:error'); | ||
// set this namespace to log via console.error | ||
error.log = console.error.bind(console); // don't forget to bind to console! | ||
error('goes to stderr'); | ||
log('still goes to stdout!'); | ||
// set all output to go via console.warn | ||
// overrides all per-namespace log settings | ||
debug.log = console.warn.bind(console); | ||
log('now goes to stderr via console.warn'); | ||
error('still goes to stderr, but via console.warn now'); | ||
``` | ||
## Authors | ||
@@ -101,0 +127,0 @@ |
Sorry, the diff of this file is not supported yet
20240
404
154