-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
109 lines (94 loc) · 2.54 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const axios = require("axios");
class Loggie {
init(config) {
this.secretKey = config.secretKey;
this.bucketId = config.bucketId;
this.channel = config.channel || "";
}
// auto collect errors
autoCollectErrors(bool) {
if (bool) {
this.isAutoCollectErrorsEnabled = true;
const vm = this;
window.addEventListener("error", function (event) {
let formattedErrorType;
const errorType = String(event.error).substr(
0,
(String(event.error) + ":").indexOf(":")
);
const validErrorTypes = {
SyntaxError: "Syntax Error",
ReferenceError: "Reference Error",
TypeError: "Type Error",
};
if (validErrorTypes[errorType]) {
formattedErrorType = validErrorTypes[errorType];
}
const message = event.message || "Message not found";
const fileName = event.filename || "Unable to get file name";
const lineno = event.lineno || "Unable to get line number";
const colno = event.colno || "Unable to get column number";
const crashdeckErrorMessage = `${message} in ${fileName} at line number: ${lineno} and column: ${colno}`;
vm.error({
message: crashdeckErrorMessage,
errorType: formattedErrorType || "",
});
});
}
}
info(payload) {
this.pushLog({
message: payload.message,
type: "info",
channel: payload.channel || this.channel || "",
});
}
debug(payload) {
this.pushLog({
message: payload.message,
type: "debug",
channel: payload.channel || this.channel || "",
});
}
warning(payload) {
this.pushLog({
message: payload.message,
type: "warning",
channel: payload.channel || this.channel || "",
});
}
error(payload) {
this.pushLog({
message: payload.message,
type: "error",
channel: payload.channel || this.channel || "",
});
}
fatal(payload) {
this.pushLog({
message: payload.message,
type: "fatal",
channel: payload.channel || this.channel || "",
});
}
pushLog(payload) {
return axios
.post(
`https://api.crashdeck.io/log-${this.bucketId}`,
{
message: payload.message,
type: payload.type,
channel: payload.channel,
},
{
headers: {
Authorization: `${this.secretKey}`,
},
}
)
.catch((err) => {
console.log(err.response.data.message);
});
}
}
module.exports = new Loggie();