var winston = require('winston'),
common = require('../common');
var exceptions = exports;
exceptions.name = 'exceptions';
exceptions.initalized = false;
var defaultConfig = exceptions.defaultConfig = {
console: {
colorize: false,
json: true,
level: 'silly'
}
};
exceptions.attach = function (options) {
options = options || {};
if (this.config) {
options = common.mixin({}, options, this.config.get('exceptions') || {});
}
if (exceptions.initalized) {
return;
}
var exceptionHandlers = [];
exceptionHandlers.push(new winston.transports.Console(options.console || defaultConfig.console));
Object.keys(options).forEach(function (name) {
if (name === 'console') {
return;
}
exceptionHandlers.push(new (winston.transports[common.capitalize(name)])(options[name]));
});
exceptions.logger = new winston.Logger({ exceptionHandlers: exceptionHandlers });
exceptions.initalized = true;
exceptions.logger.handleExceptions();
};