UNPKG

1.9 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Debug = void 0;
4const createAndTrimStackTrace = () => {
5 let stack = new Error().stack;
6 return stack && stack.split("\n").length > 2
7 ? stack.split("\n").slice(3, 7).join("\n")
8 : stack;
9};
10class Debug {
11 static SetConnection(conn) {
12 Debug.connection = conn;
13 Debug.infoLogger = (message) => Debug.connection.sendNotification("serverDebugMessage", {
14 type: "info",
15 message: message,
16 });
17 Debug.warningLogger = (message) => Debug.connection.sendNotification("serverDebugMessage", {
18 type: "warning",
19 message: message,
20 });
21 Debug.errorLogger = (message) => Debug.connection.sendNotification("serverDebugMessage", {
22 type: "error",
23 message: message,
24 });
25 }
26 static SetLoggers({ info, warning, error, }) {
27 if (info)
28 Debug.infoLogger = info;
29 if (warning)
30 Debug.warningLogger = warning;
31 if (error)
32 Debug.errorLogger = error;
33 }
34 static info(message) {
35 Debug.infoLogger(message);
36 }
37 static error(message) {
38 const stack = createAndTrimStackTrace();
39 Debug.errorLogger(`${message}\n${stack}`);
40 }
41 static warning(message) {
42 Debug.warningLogger(message);
43 }
44 static sendErrorTelemetry(message) {
45 Debug.connection &&
46 Debug.connection.sendNotification("serverDebugMessage", {
47 type: "errorTelemetry",
48 message: message,
49 });
50 }
51}
52exports.Debug = Debug;
53Debug.infoLogger = (message) => console.log("[INFO] " + message);
54Debug.warningLogger = (message) => console.warn("[WARNING] " + message);
55Debug.errorLogger = (message) => console.error("[ERROR] " + message);
56//# sourceMappingURL=debug.js.map
\No newline at end of file