Merge pull request #3011 from simianhacker/fix/error-logging

Fixing the JSON Logger
This commit is contained in:
Rashid Khan 2015-02-12 11:22:13 -07:00
commit c877687589
4 changed files with 19 additions and 5 deletions

View file

@ -68,7 +68,7 @@ server.start(function (err) {
if (config.kibana.pid_file) {
return fs.writeFile(config.kibana.pid_file, process.pid, function (err) {
if (err) {
logger.fatal('Failed to write PID file to %s', config.kibana.pid_file);
logger.fatal({ err: err }, 'Failed to write PID file to %s', config.kibana.pid_file);
process.exit(1);
}
});

View file

@ -82,7 +82,6 @@ module.exports = {
return initialization()
.then(start)
.catch(function (err) {
logger.error({ err: err });
throw err;
})
.nodeify(cb);

View file

@ -11,7 +11,7 @@ var levels = {
60: 'fatal'
};
function JSONStream (options) {
function JSONStream(options) {
options = options || {};
Writable.call(this, options);
}
@ -31,7 +31,10 @@ JSONStream.prototype._write = function (entry, encoding, callback) {
'response': entry.res
};
if (entry.error) output.error = entry.err;
if (entry.err) {
output.error = entry.err;
if (!output.message) output.message = output.error.message;
}
process.stdout.write(JSON.stringify(output) + "\n");
callback();

View file

@ -1,5 +1,7 @@
var config = require('../config');
var elasticsearch = require('elasticsearch');
var logger = require('./logger');
var _ = require('lodash');
var util = require('util');
var url = require('url');
var uri = url.parse(config.elasticsearch);
@ -7,6 +9,16 @@ if (config.kibana.kibana_elasticsearch_username && config.kibana.kibana_elastics
uri.auth = util.format('%s:%s', config.kibana.kibana_elasticsearch_username, config.kibana.kibana_elasticsearch_password);
}
module.exports = new elasticsearch.Client({
host: url.format(uri)
host: url.format(uri),
log: function (config) {
this.error = function (err) {
logger.error({ err: err });
};
this.warning = _.bindKey(logger, 'warn');
this.info = _.noop;
this.debug = _.noop;
this.trace = _.noop;
this.close = _.noop;
}
});