From da923ae75dcef85a789b282e8597bed9e8e8f1de Mon Sep 17 00:00:00 2001 From: Misha Wolfson Date: Thu, 15 Dec 2016 17:52:46 -0500 Subject: [PATCH] Fix defaults resolution when shortcut settings are passed to bunyan config --- lib/config.js | 16 +++++----------- lib/logger.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 12 deletions(-) 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()