Add logging for module registration

This commit is contained in:
Andrew Stewart 2014-11-05 14:24:07 -08:00
parent f5e427614b
commit c43978bea2
4 changed files with 29 additions and 9 deletions

View File

@ -15,8 +15,6 @@ var Logger = require('./logger'),
Config = require('./config'), Config = require('./config'),
Utils = require('./utils'); Utils = require('./utils');
Logger.setup();
var Cylon = module.exports = { var Cylon = module.exports = {
Logger: Logger, Logger: Logger,
Driver: require('./driver'), Driver: require('./driver'),

View File

@ -75,3 +75,6 @@ var setLogLevel = function(level) {
Logger[level] = function() {}; Logger[level] = function() {};
}); });
} }
Logger.setup();

View File

@ -12,6 +12,8 @@
"use strict"; "use strict";
var Logger = require('./logger');
var missingModuleError = function(module) { var missingModuleError = function(module) {
var string = "Cannot find the '" + module + "' module.\n"; var string = "Cannot find the '" + module + "' module.\n";
string += "This problem might be fixed by installing it with 'npm install " + module + "' and trying again."; string += "This problem might be fixed by installing it with 'npm install " + module + "' and trying again.";
@ -44,14 +46,15 @@ var Registry = module.exports = {
this.data[module] = { this.data[module] = {
module: pkg, module: pkg,
adaptors: pkg.adaptors || [], adaptors: pkg.adaptors || [],
drivers: pkg.drivers || [] drivers: pkg.drivers || [],
dependencies: pkg.dependencies || []
}; };
if (pkg.dependencies && Array.isArray(pkg.dependencies)) { this.logRegistration(module, this.data[module]);
pkg.dependencies.forEach(function(dep) {
Registry.register(dep); this.data[module].dependencies.forEach(function(dep) {
}); Registry.register(dep);
} });
return this.data[module].module; return this.data[module].module;
}, },
@ -72,6 +75,21 @@ var Registry = module.exports = {
return this.data[module].module; return this.data[module].module;
}, },
logRegistration: function(name) {
var module = this.data[name];
Logger.debug("Registering module " + name);
['adaptors', 'drivers', 'dependencies'].forEach(function(field) {
if (module[field].length) {
Logger.debug(" " + field + ":");
module[field].forEach(function(item) {
Logger.debug(" - " + item);
});
}
});
},
search: function(entry, value) { search: function(entry, value) {
for (var name in this.data) { for (var name in this.data) {
var repo = this.data[name]; var repo = this.data[name];

View File

@ -28,7 +28,8 @@ describe("Registry", function() {
"./../spec/support/mock_module.js": { "./../spec/support/mock_module.js": {
module: module, module: module,
drivers: ['test-driver'], drivers: ['test-driver'],
adaptors: ['test-adaptor'] adaptors: ['test-adaptor'],
dependencies: []
} }
}); });
}); });