alapa
Version:
A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.
85 lines (84 loc) • 3.1 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const path_1 = __importDefault(require("path"));
const mics_1 = require("./mics");
const colors = {
DEBUG: "\x1b[37m", // white
INFO: "\x1b[34m", // blue
WARNING: "\x1b[33m", // yellow
ERROR: "\x1b[31m", // red
SUCCESS: "\x1b[32m", // green
RESET: "\x1b[0m", // reset to default color
};
const LoggerFunction = (level, type, settings, ...message) => {
const logLevel = 5 /* LOG_LEVEL.SUCCESS */;
if (level > logLevel)
return;
// Define color codes for each log level
const levelColors = {
[4 /* LOG_LEVEL.DEBUG */]: colors.DEBUG,
[3 /* LOG_LEVEL.INFO */]: colors.INFO,
[2 /* LOG_LEVEL.WARNING */]: colors.WARNING,
[1 /* LOG_LEVEL.ERROR */]: colors.ERROR,
[5 /* LOG_LEVEL.SUCCESS */]: colors.SUCCESS,
};
if (settings?.noConsole !== true) {
const logMessage = settings?.noColor
? `[${type.toUpperCase()}] ${message.join(" ")}`
: `${levelColors[level]}[${type.toUpperCase()}] ${message.join(" ")}${colors.RESET}`;
if (level >= 4 /* LOG_LEVEL.DEBUG */) {
console.debug(logMessage);
}
else if (level >= 3 /* LOG_LEVEL.INFO */) {
console.info(logMessage);
}
else if (level >= 2 /* LOG_LEVEL.WARNING */) {
console.warn(logMessage);
}
else if (level >= 1 /* LOG_LEVEL.ERROR */) {
console.error(logMessage);
}
else if (level >= 5 /* LOG_LEVEL.SUCCESS */) {
console.log(logMessage);
}
}
if (settings?.noFile !== true) {
for (const msg of message) {
const formattedMessage = `${msg}`;
(0, mics_1.logToFile)(formattedMessage, type, path_1.default.resolve("logs", "application.log"));
}
}
};
class Logger {
static log(...message) {
LoggerFunction(4 /* LOG_LEVEL.DEBUG */, "debug", undefined, ...message);
}
static error(...message) {
LoggerFunction(1 /* LOG_LEVEL.ERROR */, "error", undefined, ...message);
return new Error(message.join("\n"));
}
static warn(...message) {
LoggerFunction(2 /* LOG_LEVEL.WARNING */, "warn", undefined, ...message);
}
static info(...message) {
LoggerFunction(3 /* LOG_LEVEL.INFO */, "info", undefined, ...message);
}
static debug(...message) {
LoggerFunction(4 /* LOG_LEVEL.DEBUG */, "debug", undefined, ...message);
}
static success(...message) {
LoggerFunction(5 /* LOG_LEVEL.SUCCESS */, "success", { noFile: true }, ...message);
}
static throw(...message) {
LoggerFunction(1 /* LOG_LEVEL.ERROR */, "error", {
noConsole: true,
}, ...message);
return new Error(message.join("\n"));
}
}
exports.Logger = Logger;
;