diff --git a/lib/config.js b/lib/config.js index 4aa01e9..421f19c 100644 --- a/lib/config.js +++ b/lib/config.js @@ -31,24 +31,18 @@ nconf.defaults({ port: 80, bunyan: { name: nconf.get('name') || 'spserver', - streams: [{ - stream: 'process.stdout', - level: 'info' - } - ] + stream: 'process.stdout', + level: 'info', }, }, development: { port: 3001, bunyan: { name: nconf.get('name') || 'spserver', - streams: [{ - stream: 'process.stdout', - level: 'debug' - } - ] + stream: 'process.stdout', + level: 'debug', }, - } + }, }); module.exports = nconf; diff --git a/lib/logger.js b/lib/logger.js index 8bd3387..7ae8c07 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -13,7 +13,19 @@ var output; if (config.get('bunyan') || config.get(env + ':use_bunyan')) { var settings = _.cloneDeep(config.get(env + ':bunyan')); - // Stream can be specified either in settings.streams[ix] or globally in settings.stream + // Stream can be specified either in settings.streams[ix] or globally in settings.stream, but not + // both. Since the defaults specify stetings.stream, if the user specifies anything of vaulue + // in settings.streams, we should delete the global defaults, because bunyan gets angry if there + // are multiple keys + if (_.has(settings, 'streams')) { + if (settings.streams) { + delete settings.stream; + delete settings.level; + } else { + delete settings.streams; + } + } + _([settings.streams, settings]) .flatten() .compact()