2023-07-29 20:32:17 +02:00
|
|
|
//SVR.JS LOG HIGHLIGHTER
|
|
|
|
|
2024-08-26 07:34:07 +02:00
|
|
|
const readline = require("readline");
|
2023-07-29 20:32:17 +02:00
|
|
|
|
2024-08-26 07:34:07 +02:00
|
|
|
const args = process.argv;
|
|
|
|
for (
|
|
|
|
let i =
|
|
|
|
process.argv[0].indexOf("node") > -1 || process.argv[0].indexOf("bun") > -1
|
|
|
|
? 2
|
|
|
|
: 1;
|
|
|
|
i < args.length;
|
|
|
|
i++
|
|
|
|
) {
|
|
|
|
if (
|
|
|
|
args[i] == "-h" ||
|
|
|
|
args[i] == "--help" ||
|
|
|
|
args[i] == "-?" ||
|
|
|
|
args[i] == "/h" ||
|
|
|
|
args[i] == "/?"
|
|
|
|
) {
|
2023-07-29 20:32:17 +02:00
|
|
|
console.log("SVR.JS log highlighter usage:");
|
2024-08-26 07:34:07 +02:00
|
|
|
console.log(
|
2024-09-01 21:54:42 +02:00
|
|
|
"<some process> | node loghighlight.js [-h] [--help] [-?] [/h] [/?]"
|
2024-08-26 07:34:07 +02:00
|
|
|
);
|
2023-07-29 20:32:17 +02:00
|
|
|
console.log("-h -? /h /? --help -- Displays help");
|
|
|
|
process.exit(0);
|
|
|
|
} else {
|
|
|
|
console.log("Unrecognized argument: " + args[i]);
|
|
|
|
console.log("SVR.JS log highlighter usage:");
|
2024-08-26 07:34:07 +02:00
|
|
|
console.log(
|
2024-09-01 21:54:42 +02:00
|
|
|
"<some process> | node loghighlight.js [-h] [--help] [-?] [/h] [/?]"
|
2024-08-26 07:34:07 +02:00
|
|
|
);
|
2023-07-29 20:32:17 +02:00
|
|
|
console.log("-h -? /h /? --help -- Displays help");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-26 07:34:07 +02:00
|
|
|
const rl = readline.createInterface({
|
2023-07-29 20:32:17 +02:00
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout,
|
|
|
|
terminal: false,
|
2024-09-01 21:54:42 +02:00
|
|
|
prompt: ""
|
2023-07-29 20:32:17 +02:00
|
|
|
});
|
|
|
|
rl.prompt();
|
2024-08-26 07:34:07 +02:00
|
|
|
rl.on("line", (line) => {
|
2023-07-29 20:32:17 +02:00
|
|
|
viewLog([line]);
|
|
|
|
});
|
|
|
|
|
|
|
|
function viewLog(log) {
|
2024-08-26 07:34:07 +02:00
|
|
|
if (log[log.length - 1] == "") log.pop();
|
|
|
|
if (log[0] == "") log.shift();
|
|
|
|
for (var i = 0; i < log.length; i++) {
|
|
|
|
if (log[i].indexOf("SERVER REQUEST MESSAGE") != -1) {
|
|
|
|
log[i] =
|
|
|
|
log[i].replace(
|
|
|
|
"SERVER REQUEST MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[34m\x1b[1mSERVER REQUEST MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
) + "\x1b[37m\x1b[0m";
|
|
|
|
} else if (log[i].indexOf("SERVER RESPONSE MESSAGE") != -1) {
|
|
|
|
log[i] =
|
|
|
|
log[i].replace(
|
|
|
|
"SERVER RESPONSE MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[32m\x1b[1mSERVER RESPONSE MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
) + "\x1b[37m\x1b[0m";
|
|
|
|
} else if (log[i].indexOf("SERVER RESPONSE ERROR MESSAGE") != -1) {
|
|
|
|
log[i] =
|
|
|
|
log[i].replace(
|
|
|
|
"SERVER RESPONSE ERROR MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[31m\x1b[1mSERVER RESPONSE ERROR MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
) + "\x1b[37m\x1b[0m";
|
|
|
|
} else if (log[i].indexOf("SERVER ERROR MESSAGE") != -1) {
|
|
|
|
log[i] =
|
|
|
|
log[i].replace(
|
|
|
|
"SERVER ERROR MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[41m\x1b[1mSERVER ERROR MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
) + "\x1b[40m\x1b[0m";
|
|
|
|
} else if (log[i].indexOf("SERVER WARNING MESSAGE") != -1) {
|
|
|
|
log[i] =
|
|
|
|
log[i].replace(
|
|
|
|
"SERVER WARNING MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[43m\x1b[1mSERVER WARNING MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
) + "\x1b[40m\x1b[0m";
|
|
|
|
} else if (log[i].indexOf("SERVER MESSAGE") != -1) {
|
|
|
|
log[i] = log[i].replace(
|
|
|
|
"SERVER MESSAGE",
|
2024-09-01 21:54:42 +02:00
|
|
|
"\x1b[1mSERVER MESSAGE\x1b[22m"
|
2024-08-26 07:34:07 +02:00
|
|
|
);
|
2023-07-29 20:32:17 +02:00
|
|
|
}
|
2024-08-26 07:34:07 +02:00
|
|
|
console.log(log[i]);
|
|
|
|
}
|
2023-07-29 20:32:17 +02:00
|
|
|
}
|