3 var env
= require('gitter-web-env');
4 var logger
= env
.logger
;
5 var config
= env
.config
;
6 var elasticsearch
= require('elasticsearch');
7 var Promise
= require('bluebird');
8 var debug
= require('debug')('gitter:infra:elasticsearch');
10 function ElasticSearchLoggingAdapter(/*config*/) {}
12 ElasticSearchLoggingAdapter
.prototype.error = function(error
) {
13 logger
.error('es: error ' + error
, { exception
: error
});
16 ElasticSearchLoggingAdapter
.prototype.warning = function(message
) {
17 logger
.warn('es: ' + message
);
20 ElasticSearchLoggingAdapter
.prototype.info = function(message
) {
21 debug('es: ' + message
);
24 ElasticSearchLoggingAdapter
.prototype.debug = function(message
) {
28 ElasticSearchLoggingAdapter
.prototype.trace = function(
31 body
/*, responseBody, responseStatus*/
33 debug('trace: method=%s url=%s, body=%j', method
, requestUrl
&& requestUrl
.path
, body
);
35 ElasticSearchLoggingAdapter
.prototype.close = function() {};
39 var promise
= new Promise(function() {
40 resolve
= arguments
[0];
41 reject
= arguments
[1];
50 module
.exports
= new elasticsearch
.Client({
51 hosts
: config
.get('elasticsearchTypeahead:hosts'),
52 // Warning: possible memory leak: https://github.com/elasticsearch/elasticsearch-js/issues/71
53 sniffOnStart
: config
.get('elasticsearch:sniffOnStart'),
54 sniffInterval
: 300000,
57 log
: ElasticSearchLoggingAdapter