-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (41 loc) · 1.78 KB
/
index.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Created by marlonchavarria on 12/26/15.
*/
"use strict";
var log4js = require('log4js');
var request = require("request");
var consoleLog = console.log.bind(console);
function httpRequestAppender(config) {
return function (loggingEvent) {
//validate configuration
if (config != null && config.httpRequest != null && config.httpRequest.endpoint != null &&
config.httpRequest.method != null && config.httpRequest.contentType != null &&
config.params != null && config.paramUsedToSendLoggingEvent) {
var options = { method: config.httpRequest.method,
url: config.httpRequest.endpoint,
headers: { 'content-type': config.httpRequest.contentType}
};
if (config.httpRequest.contentType === 'application/x-www-form-urlencoded') {
options.form = config.params
options.form[config.paramUsedToSendLoggingEvent] = loggingEvent;
} else if (config.httpRequest.contentType === 'application/json') {
options.body = config.params;
options.body[config.paramUsedToSendLoggingEvent] = loggingEvent;
} else {
consoleLog("ContentType: ".concat(config.httpRequest.contentType, " is not supported"));
}
}else{
consoleLog("httpRequestAppender: Invalid Configuration please check");
return;
}
request(options, function (error, response, body) {
if (error) console.log("Error from httpRequestAppender: ".concat(JSON.stringify(error)));
});
};
}
function configure(config) {
return httpRequestAppender(config);
}
exports.name = 'httpRequestAppender';
exports.appender = httpRequestAppender;
exports.configure = configure;