fixed a few bugs now that the class names are properly being set.

This commit is contained in:
Spencer Alger
2013-10-29 20:01:15 -07:00
parent 286a08c8c2
commit 4273ffc2c7
2 changed files with 21 additions and 12 deletions

View File

@ -41,6 +41,11 @@ var defaultClasses = {
};
var defaultConfig = {
loggers: [
{
level: 'warning'
}
],
hosts: [
{
host: 'localhost',
@ -86,24 +91,28 @@ connectors = _.transform(connectors, function (note, connector, name) {
function ClientConfig(config) {
_.extend(this, defaultConfig, config);
if (this.log) {
// treat log as an alias for loggers in the config.
this.loggers = this.log;
delete this.log;
}
// validate connectionClass
if (typeof this.connectionClass === 'string') {
this.connectionClass = connectors[_.studlyCase(this.connectionClass)];
}
if (typeof this.connectionClass !== 'function') {
if (typeof connectors[this.connectionClass] === 'function') {
this.connectionClass = connectors[this.connectionClass];
} else {
throw new TypeError('Invalid connectionClass "' + this.connectionClass + '". ' +
throw new TypeError('Invalid connectionClass "' + this.connectionClass + '". ' +
'Expected a constructor or one of ' + _.keys(connectors).join(', '));
}
}
// validate selector
if (typeof this.selector === 'string') {
this.selector = selectors[_.camelCase(this.selector)];
}
if (typeof this.selector !== 'function') {
if (_.has(selectors, this.selector)) {
this.selector = selectors[this.selector];
} else {
throw new TypeError('Invalid Selector "' + this.selector + '". ' +
throw new TypeError('Invalid Selector "' + this.selector + '". ' +
'Expected a function or one of ' + _.keys(selectors).join(', '));
}
}
_.each(defaultClasses, function (DefaultClass, prop) {

View File

@ -31,7 +31,7 @@ function Log(config) {
this.config = config || {};
var i;
var output = _.isPlainObject(config.log) ? config.log : 'warning';
var output = config.loggers ? config.loggers : 'warning';
if (_.isString(output) || _.isFinite(output)) {
output = [
@ -188,7 +188,7 @@ Log.prototype.addOutput = function (config) {
delete config.level;
config.levels = levels;
var Logger = loggers[config.type];
var Logger = loggers[_.studlyCase(config.type)];
if (Logger) {
return new Logger(config, this);
} else {