|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports = module.exports = createDebug.debug = createDebug['default'] = createDebug; |
|
exports.coerce = coerce; |
|
exports.disable = disable; |
|
exports.enable = enable; |
|
exports.enabled = enabled; |
|
exports.humanize = require('ms'); |
|
|
|
|
|
|
|
|
|
|
|
exports.names = []; |
|
exports.skips = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.formatters = {}; |
|
|
|
|
|
|
|
|
|
|
|
var prevTime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function selectColor(namespace) { |
|
var hash = 0, i; |
|
|
|
for (i in namespace) { |
|
hash = ((hash << 5) - hash) + namespace.charCodeAt(i); |
|
hash |= 0; |
|
} |
|
|
|
return exports.colors[Math.abs(hash) % exports.colors.length]; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createDebug(namespace) { |
|
|
|
function debug() { |
|
|
|
if (!debug.enabled) return; |
|
|
|
var self = debug; |
|
|
|
|
|
var curr = +new Date(); |
|
var ms = curr - (prevTime || curr); |
|
self.diff = ms; |
|
self.prev = prevTime; |
|
self.curr = curr; |
|
prevTime = curr; |
|
|
|
|
|
var args = new Array(arguments.length); |
|
for (var i = 0; i < args.length; i++) { |
|
args[i] = arguments[i]; |
|
} |
|
|
|
args[0] = exports.coerce(args[0]); |
|
|
|
if ('string' !== typeof args[0]) { |
|
|
|
args.unshift('%O'); |
|
} |
|
|
|
|
|
var index = 0; |
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { |
|
|
|
if (match === '%%') return match; |
|
index++; |
|
var formatter = exports.formatters[format]; |
|
if ('function' === typeof formatter) { |
|
var val = args[index]; |
|
match = formatter.call(self, val); |
|
|
|
|
|
args.splice(index, 1); |
|
index--; |
|
} |
|
return match; |
|
}); |
|
|
|
|
|
exports.formatArgs.call(self, args); |
|
|
|
var logFn = debug.log || exports.log || console.log.bind(console); |
|
logFn.apply(self, args); |
|
} |
|
|
|
debug.namespace = namespace; |
|
debug.enabled = exports.enabled(namespace); |
|
debug.useColors = exports.useColors(); |
|
debug.color = selectColor(namespace); |
|
|
|
|
|
if ('function' === typeof exports.init) { |
|
exports.init(debug); |
|
} |
|
|
|
return debug; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enable(namespaces) { |
|
exports.save(namespaces); |
|
|
|
exports.names = []; |
|
exports.skips = []; |
|
|
|
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); |
|
var len = split.length; |
|
|
|
for (var i = 0; i < len; i++) { |
|
if (!split[i]) continue; |
|
namespaces = split[i].replace(/\*/g, '.*?'); |
|
if (namespaces[0] === '-') { |
|
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); |
|
} else { |
|
exports.names.push(new RegExp('^' + namespaces + '$')); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function disable() { |
|
exports.enable(''); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function enabled(name) { |
|
var i, len; |
|
for (i = 0, len = exports.skips.length; i < len; i++) { |
|
if (exports.skips[i].test(name)) { |
|
return false; |
|
} |
|
} |
|
for (i = 0, len = exports.names.length; i < len; i++) { |
|
if (exports.names[i].test(name)) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function coerce(val) { |
|
if (val instanceof Error) return val.stack || val.message; |
|
return val; |
|
} |
|
|