feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -12,24 +12,24 @@ const { LogType } = require("./Logger");
/** @typedef {import("./Logger").LogTypeEnum} LogTypeEnum */
/** @typedef {function(string): boolean} FilterFunction */
/** @typedef {function(string, LogTypeEnum, any[]): void} LoggingFunction */
/** @typedef {function(string, LogTypeEnum, EXPECTED_ANY[]=): void} LoggingFunction */
/**
* @typedef {object} LoggerConsole
* @property {function(): void} clear
* @property {function(): void} trace
* @property {(...args: any[]) => void} info
* @property {(...args: any[]) => void} log
* @property {(...args: any[]) => void} warn
* @property {(...args: any[]) => void} error
* @property {(...args: any[]) => void=} debug
* @property {(...args: any[]) => void=} group
* @property {(...args: any[]) => void=} groupCollapsed
* @property {(...args: any[]) => void=} groupEnd
* @property {(...args: any[]) => void=} status
* @property {(...args: any[]) => void=} profile
* @property {(...args: any[]) => void=} profileEnd
* @property {(...args: any[]) => void=} logTime
* @property {(...args: EXPECTED_ANY[]) => void} info
* @property {(...args: EXPECTED_ANY[]) => void} log
* @property {(...args: EXPECTED_ANY[]) => void} warn
* @property {(...args: EXPECTED_ANY[]) => void} error
* @property {(...args: EXPECTED_ANY[]) => void=} debug
* @property {(...args: EXPECTED_ANY[]) => void=} group
* @property {(...args: EXPECTED_ANY[]) => void=} groupCollapsed
* @property {(...args: EXPECTED_ANY[]) => void=} groupEnd
* @property {(...args: EXPECTED_ANY[]) => void=} status
* @property {(...args: EXPECTED_ANY[]) => void=} profile
* @property {(...args: EXPECTED_ANY[]) => void=} profileEnd
* @property {(...args: EXPECTED_ANY[]) => void=} logTime
*/
/**
@@ -95,7 +95,7 @@ module.exports = ({ level = "info", debug = false, console }) => {
/**
* @param {string} name name of the logger
* @param {LogTypeEnum} type type of the log entry
* @param {any[]} args arguments of the log entry
* @param {EXPECTED_ANY[]=} args arguments of the log entry
* @returns {void}
*/
const logger = (name, type, args) => {
@@ -103,12 +103,10 @@ module.exports = ({ level = "info", debug = false, console }) => {
if (Array.isArray(args)) {
if (args.length > 0 && typeof args[0] === "string") {
return [`[${name}] ${args[0]}`, ...args.slice(1)];
} else {
return [`[${name}]`, ...args];
}
} else {
return [];
return [`[${name}]`, ...args];
}
return [];
};
const debug = debugFilters.some(f => f(name));
switch (type) {
@@ -167,8 +165,11 @@ module.exports = ({ level = "info", debug = false, console }) => {
break;
case LogType.time: {
if (!debug && loglevel > LogLevel.log) return;
const ms = args[1] * 1000 + args[2] / 1000000;
const msg = `[${name}] ${args[0]}: ${ms} ms`;
const [label, start, end] =
/** @type {[string, number, number]} */
(args);
const ms = start * 1000 + end / 1000000;
const msg = `[${name}] ${label}: ${ms} ms`;
if (typeof console.logTime === "function") {
console.logTime(msg);
} else {
@@ -195,15 +196,13 @@ module.exports = ({ level = "info", debug = false, console }) => {
case LogType.status:
if (!debug && loglevel > LogLevel.info) return;
if (typeof console.status === "function") {
if (args.length === 0) {
if (!args || args.length === 0) {
console.status();
} else {
console.status(...labeledArgs());
}
} else {
if (args.length !== 0) {
console.info(...labeledArgs());
}
} else if (args && args.length !== 0) {
console.info(...labeledArgs());
}
break;
default: