rokojori-godot/rokojori-cpp-generator/builds/library/RJLog.js

83 lines
3.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RJLog = void 0;
const LogColors_1 = require("./LogColors");
const Texts_1 = require("./Texts");
class RJLog {
static _parseLineResult(line) {
let result = RJLog.matcherWithFunction.exec(line) ||
RJLog.matcherFile.exec(line) ||
RJLog.matcherAnonymous.exec(line);
return result;
}
static _parseLine(line) {
let result = RJLog._parseLineResult(line);
if (result) {
return " " + result[1] + "(" + result[2] + ") ";
}
return line;
}
static logError(e) {
console.log("\n" + RJLog._formatErrorMessage(e.stack));
}
static _formatErrorMessage(stackTrace, color = RJLog.errorMessageColor) {
let lines = Texts_1.Texts.splitLines(stackTrace);
let output = [color];
lines.forEach((line, index) => {
let lineInfo = RJLog._parseLine(line);
output.push(lineInfo);
if (index !== lines.length - 1) {
output.push("\n");
}
});
output.push(RJLog.resetColor);
return output.join("");
}
static getLineInfo(color = RJLog.logColor, stackTrace, lineIndex = 3) {
stackTrace = stackTrace || (new Error().stack + "");
let lines = Texts_1.Texts.splitLines(stackTrace);
let result = null;
while (!result && lineIndex < lines.length) {
let line = lines[lineIndex];
result = RJLog._parseLineResult(line);
lineIndex++;
}
if (!result) {
console.log(stackTrace);
return color + " <Unknown> " + RJLog.resetColor;
}
return color + " " + result[1] + "(" + result[2] + ") " + RJLog.resetColor;
}
static error(...params) {
if (RJLog.logAlwaysLineInfo || typeof process === "object") {
let lineInfo = RJLog.getLineInfo(RJLog.errorColor);
console.log("\n" + lineInfo);
}
console.error.apply(console, params);
}
static warn(...params) {
if (RJLog.logAlwaysLineInfo || typeof process === "object") {
let lineInfo = RJLog.getLineInfo(RJLog.warnColor);
console.log("\n" + lineInfo);
}
console.warn.apply(console, params);
}
static log(...params) {
if (RJLog.logAlwaysLineInfo || typeof process === "object") {
let lineInfo = RJLog.getLineInfo();
console.log("\n" + lineInfo);
}
console.log.apply(console, params);
}
}
exports.RJLog = RJLog;
RJLog.errorColor = LogColors_1.LogColors.red_Background;
RJLog.errorMessageColor = LogColors_1.LogColors.red_Foreground;
RJLog.warnColor = LogColors_1.LogColors.yellow_Background;
RJLog.logColor = LogColors_1.LogColors.gray_Background;
RJLog.resetColor = LogColors_1.LogColors.reset;
RJLog.matcherWithFunction = /^\s+at\s(.+)\s\(.+?:(\d+:\d+)\)/;
RJLog.matcherFile = /\(.+?\\(\w+)\.js:(\d+:\d+)\)/;
RJLog.matcherAnonymous = /^\s+at\s(.+)\s\((.+)\)/;
RJLog.logAlwaysLineInfo = true;
//# sourceMappingURL=RJLog.js.map