-
Notifications
You must be signed in to change notification settings - Fork 0
/
reportFramework.js
43 lines (39 loc) · 1.16 KB
/
reportFramework.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
/**
*
* @param {Number} aid Your app id given to you
* @param {String} [reportBy="Logger"] The log is reported by the param specified
*/
var Logger = function (aid, reportBy) {
this.serverUrl = 'http://localhost:3000/logs';
this.aid = aid;
this.reportBy = typeof (reportBy) == 'string' ? reportBy : "Logger";
}
/**
* @param {String} message The message to be logged
* @param {String} [logType = "Error"] The type of the log
*/
Logger.prototype.log = function (message, logType) {
var self = this;
if (typeof (message) == 'object') {
if (message.toString() != "[object Object]") {
message = message.toString();
}
else {
message = JSON.stringify(message);
}
}
return new Promise((resolve, reject) => {
fetch(this.serverUrl, {
method: "post",
body: JSON.stringify({
aid: self.aid,
message: message,
logType: logType,
reportBy: self.reportBy
})
})
.then(res => res.json())
.then(data => resolve(data))
.catch(err => reject(err));
})
}