1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Debug = void 0;
|
4 | const 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 | };
|
10 | class 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 | }
|
52 | exports.Debug = Debug;
|
53 | Debug.infoLogger = (message) => console.log("[INFO] " + message);
|
54 | Debug.warningLogger = (message) => console.warn("[WARNING] " + message);
|
55 | Debug.errorLogger = (message) => console.error("[ERROR] " + message);
|
56 |
|
\ | No newline at end of file |