Skip to content

Commit

Permalink
Merge pull request #3011 from simianhacker/fix/error-logging
Browse files Browse the repository at this point in the history
Fixing the JSON Logger
  • Loading branch information
rashidkpc committed Feb 12, 2015
2 parents aafba0d + 21c760d commit c877687
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/server/bin/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
1 change: 0 additions & 1 deletion src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ module.exports = {
return initialization()
.then(start)
.catch(function (err) {
logger.error({ err: err });
throw err;
})
.nodeify(cb);
Expand Down
7 changes: 5 additions & 2 deletions src/server/lib/JSONStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var levels = {
60: 'fatal'
};

function JSONStream (options) {
function JSONStream(options) {
options = options || {};
Writable.call(this, options);
}
Expand All @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/server/lib/elasticsearch_client.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
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);
if (config.kibana.kibana_elasticsearch_username && config.kibana.kibana_elasticsearch_password) {
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;
}
});

0 comments on commit c877687

Please sign in to comment.