Fix defaults resolution when shortcut settings are passed to bunyan config
This commit is contained in:
parent
800e02aa40
commit
1cf7c4a7bb
2 changed files with 18 additions and 12 deletions
|
@ -31,24 +31,18 @@ nconf.defaults({
|
|||
port: 80,
|
||||
bunyan: {
|
||||
name: nconf.get('name') || 'spserver',
|
||||
streams: [{
|
||||
stream: 'process.stdout',
|
||||
level: 'info'
|
||||
}
|
||||
]
|
||||
level: 'info',
|
||||
},
|
||||
},
|
||||
development: {
|
||||
port: 3001,
|
||||
bunyan: {
|
||||
name: nconf.get('name') || 'spserver',
|
||||
streams: [{
|
||||
stream: 'process.stdout',
|
||||
level: 'debug'
|
||||
}
|
||||
]
|
||||
level: 'debug',
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = nconf;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue