Perform early return in Log ctor.
This commit is contained in:
47
src/lib/log.js
Executable file → Normal file
47
src/lib/log.js
Executable file → Normal file
@ -18,36 +18,35 @@ var EventEmitter = require('events').EventEmitter;
|
|||||||
*/
|
*/
|
||||||
function Log(config) {
|
function Log(config) {
|
||||||
config = config || {};
|
config = config || {};
|
||||||
|
if (!config.log) return;
|
||||||
|
|
||||||
var i;
|
var i;
|
||||||
var outputs;
|
var outputs;
|
||||||
|
|
||||||
if (config.log) {
|
if (_.isArrayOfStrings(config.log)) {
|
||||||
if (_.isArrayOfStrings(config.log)) {
|
outputs = [{
|
||||||
outputs = [{
|
levels: config.log
|
||||||
levels: config.log
|
}];
|
||||||
}];
|
} else {
|
||||||
} else {
|
outputs = _.createArray(config.log, function (val) {
|
||||||
outputs = _.createArray(config.log, function (val) {
|
if (_.isPlainObject(val)) {
|
||||||
if (_.isPlainObject(val)) {
|
return val;
|
||||||
return val;
|
}
|
||||||
}
|
if (typeof val === 'string') {
|
||||||
if (typeof val === 'string') {
|
return {
|
||||||
return {
|
level: val
|
||||||
level: val
|
};
|
||||||
};
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!outputs) {
|
if (!outputs) {
|
||||||
throw new TypeError('Invalid logging output config. Expected either a log level, array of log levels, ' +
|
throw new TypeError('Invalid logging output config. Expected either a log level, array of log levels, ' +
|
||||||
'a logger config object, or an array of logger config objects.');
|
'a logger config object, or an array of logger config objects.');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < outputs.length; i++) {
|
for (i = 0; i < outputs.length; i++) {
|
||||||
this.addOutput(outputs[i]);
|
this.addOutput(outputs[i]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_.inherits(Log, EventEmitter);
|
_.inherits(Log, EventEmitter);
|
||||||
|
|||||||
Reference in New Issue
Block a user