Fix defaults resolution when shortcut settings are passed to bunyan config

This commit is contained in:
Misha Wolfson 2016-12-15 17:52:46 -05:00
parent 800e02aa40
commit 1cf7c4a7bb
2 changed files with 18 additions and 12 deletions

View file

@ -31,24 +31,18 @@ nconf.defaults({
port: 80, port: 80,
bunyan: { bunyan: {
name: nconf.get('name') || 'spserver', name: nconf.get('name') || 'spserver',
streams: [{ stream: 'process.stdout',
stream: 'process.stdout', level: 'info',
level: 'info'
}
]
}, },
}, },
development: { development: {
port: 3001, port: 3001,
bunyan: { bunyan: {
name: nconf.get('name') || 'spserver', name: nconf.get('name') || 'spserver',
streams: [{ stream: 'process.stdout',
stream: 'process.stdout', level: 'debug',
level: 'debug'
}
]
}, },
} },
}); });
module.exports = nconf; module.exports = nconf;

View file

@ -13,7 +13,19 @@ var output;
if (config.get('bunyan') || config.get(env + ':use_bunyan')) { if (config.get('bunyan') || config.get(env + ':use_bunyan')) {
var settings = _.cloneDeep(config.get(env + ':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]) _([settings.streams, settings])
.flatten() .flatten()
.compact() .compact()