forked from maksrom/javascript-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
executable file
·37 lines (32 loc) · 995 Bytes
/
client.js
File metadata and controls
executable file
·37 lines (32 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var elasticsearch = require('elasticsearch');
var config = require('config');
const log = require('log')();
// logger from
// http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/logging.html
function LogToBunyan(config) {
// config is the object passed to the client constructor.
this.error = log.error.bind(log);
this.warning = log.warn.bind(log);
this.info = log.info.bind(log);
this.debug = log.debug.bind(log);
this.trace = function(method, requestUrl, body, responseBody, responseStatus) {
log.trace({
method: method,
requestUrl: requestUrl,
body: body,
responseBody: responseBody,
responseStatus: responseStatus
});
};
this.close = function() {
/* bunyan's loggers do not need to be closed */
};
}
var client;
module.exports = function() {
if (!client) client = new elasticsearch.Client({
host: config.elastic.host,
log: LogToBunyan
});
return client;
};