From 4273ffc2c7ac42422b3188ab3176191b95a72456 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 29 Oct 2013 20:01:15 -0700 Subject: [PATCH] fixed a few bugs now that the class names are properly being set. --- src/lib/client_config.js | 29 +++++++++++++++++++---------- src/lib/log.js | 4 ++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/lib/client_config.js b/src/lib/client_config.js index fa8852633..f43aa57bc 100644 --- a/src/lib/client_config.js +++ b/src/lib/client_config.js @@ -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) { diff --git a/src/lib/log.js b/src/lib/log.js index 0a93364b5..225e51f8a 100755 --- a/src/lib/log.js +++ b/src/lib/log.js @@ -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 {