2015-02-02 09:52:31 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
var bunyan = require('bunyan');
|
|
|
|
|
|
|
|
//Get the config
|
|
|
|
var config = require('./config');
|
|
|
|
|
|
|
|
//Create our variables
|
|
|
|
var env = config.get('NODE_ENV');
|
|
|
|
var output;
|
|
|
|
|
|
|
|
if (config.get('bunyan') || config.get(env + ':use_bunyan')) {
|
|
|
|
var settings = _.cloneDeep(config.get(env + ':bunyan'));
|
|
|
|
|
2016-12-14 23:23:30 +00:00
|
|
|
// Stream can be specified either in settings.streams[ix] or globally in settings.stream
|
|
|
|
_([settings.streams, settings])
|
|
|
|
.flatten()
|
2016-12-15 22:48:24 +00:00
|
|
|
.compact()
|
2016-12-14 23:23:30 +00:00
|
|
|
.forEach(function (settingObj) {
|
|
|
|
if (settingObj.stream === 'process.stdout') {
|
|
|
|
settingObj.stream = process.stdout;
|
|
|
|
} else if (settingObj.stream === 'process.stderr') {
|
|
|
|
settingObj.stream = process.stderr;
|
|
|
|
}
|
|
|
|
});
|
2015-02-02 09:52:31 +00:00
|
|
|
|
|
|
|
output = bunyan.createLogger(settings);
|
|
|
|
} else {
|
|
|
|
output = console;
|
2016-12-14 23:04:28 +00:00
|
|
|
output.debug = console.log.bind(console);
|
2015-02-02 09:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = output;
|