Files
2023-02-03 21:56:29 +08:00

60 lines
1.5 KiB
JavaScript

'use strict'
const chalk = require('chalk');
const colorize = require('json-colorizer');
const error = chalk.bold.redBright;
const warning = chalk.keyword('orange');
const info = chalk.cyanBright;
const infoData = chalk.keyword('lightpink');
const infoKeys = chalk.keyword('lightgreen');
const infoMisc = chalk.keyword('mintcream');
// Handle common debugging functions in here
function ColoredDebugPrint(type, msg, ...data) {
console.log(type(msg), ...data);
}
global.DebugError = function (msg, ...data) {
let errmsg = 'ERROR:: ' + msg + " (=xェx=)";
ColoredDebugPrint(error, errmsg, ...data)
};
global.DebugWarn = function (msg, ...data) {
let dbgmsg = 'WARN:: ' + msg;
ColoredDebugPrint(warning, dbgmsg, ...data)
};
global.DebugInfo = function (msg, ...data) {
let dbgmsg = 'INFO:: ' + msg;
ColoredDebugPrint(info, dbgmsg, ...data)
};
global.DebugMisc = function (msg, ...data) {
let dbgmsg = 'MISC:: ' + msg;
ColoredDebugPrint(infoMisc, dbgmsg, ...data)
};
global.DebugKeys = function (msg, ...data) {
let dbgmsg = msg;
ColoredDebugPrint(infoKeys, dbgmsg, ...data)
};
global.DebugData = function (msg, ...data) {
let dbgmsg = 'DATA:: ' + msg;
ColoredDebugPrint(infoData, dbgmsg, ...data)
};
function printJSON(data, type) {
DebugData("%s JSON: \n", type);
console.log(colorize(data, {
pretty: true
}));
}
global.DebugRequest = function (data) {
printJSON(data, "Request");
}
global.DebugResponse = function (data) {
printJSON(data, "Response");
}