Skip to content

Commit 8fb8620

Browse files
authored
make node/browser js lib to send data in logstash format (#3)
1 parent 6f1fb88 commit 8fb8620

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

js/src/LogEvent.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class LogEvent
2727
*/
2828
error(message)
2929
{
30-
this.event('error', { message });
30+
return this.event('error', { message });
3131
}
3232

3333
/**
@@ -51,7 +51,7 @@ class LogEvent
5151

5252
nodeRequest(data, resolve, reject)
5353
{
54-
let params = encodeURIComponent(JSON.stringify(data));
54+
const { URL } = require('url');
5555

5656
let url = new URL(this.url);
5757
let protocol = url.protocol.replace(':', '');
@@ -64,12 +64,10 @@ class LogEvent
6464
hostname: url.hostname,
6565
port: url.port,
6666
path: url.pathname,
67-
method,
67+
method: 'POST',
6868
headers: {
69-
'Content-Type': 'application/x-www-form-urlencoded'
69+
'Content-Type': 'application/json'
7070
},
71-
agent: keepAliveAgent,
72-
timeout: 1000,
7371
checkServerIdentity: function (host, cert) {
7472
return undefined;
7573
}
@@ -98,7 +96,7 @@ class LogEvent
9896
status: e
9997
});
10098
});
101-
req.end();
99+
req.end(JSON.stringify(data));
102100
}
103101

104102
browserRequest(data, resolve, reject)
@@ -107,7 +105,7 @@ class LogEvent
107105
req.open('POST', this.url, true);
108106

109107
// Send the proper header information along with the request.
110-
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
108+
req.setRequestHeader('Content-type', 'application/json');
111109
req.withCredentials = true;
112110
req.onreadystatechange = () => {
113111
if (req.readyState == 4 && req.status == 200) {
@@ -120,7 +118,7 @@ class LogEvent
120118
});
121119
}
122120
}
123-
req.send(encodeURIComponent(JSON.stringify(data)));
121+
req.send(JSON.stringify(data));
124122
}
125123
};
126124

0 commit comments

Comments
 (0)