diff --git a/.gitignore b/.gitignore
index 76add87..b512c09 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1 @@
-node_modules
-dist
\ No newline at end of file
+node_modules
\ No newline at end of file
diff --git a/build.ts b/build.ts
new file mode 100644
index 0000000..4735892
--- /dev/null
+++ b/build.ts
@@ -0,0 +1,43 @@
+import dts from 'bun-plugin-dts';
+import Logger from '@rabbit-company/logger';
+import fs from 'fs/promises';
+
+await fs.rm('./module', {recursive: true, force: true});
+await fs.rm('./dist', {recursive: true, force: true});
+
+Logger.info('Start bulding module...');
+let moduleBuild = await Bun.build({
+ entrypoints: ['./src/logger.ts'],
+ outdir: './module',
+ target: 'browser',
+ format: 'esm',
+ plugins: [
+ dts({output: {noBanner: true}})
+ ],
+});
+
+if(moduleBuild.success){
+ Logger.info('Bulding module complete');
+}else{
+ Logger.error('Bulding module failed');
+}
+
+fs.cp('./src/index.html', './dist/index.html', {recursive: true, force: true});
+
+Logger.info('Start bundling dist...');
+let distBuild = await Bun.build({
+ entrypoints: ['./src/index.ts'],
+ outdir: './dist',
+ target: 'browser',
+ format: 'esm',
+ minify: true,
+ sourcemap: 'none', // Bun still generates incorrect sourcemaps
+ plugins: [],
+});
+
+if(distBuild.success){
+ Logger.info('Bundling dist complete');
+}else{
+ Logger.error('Bundling dist failed');
+ Logger.error(distBuild.logs);
+}
\ No newline at end of file
diff --git a/bun.lockb b/bun.lockb
new file mode 100755
index 0000000..3e775f5
Binary files /dev/null and b/bun.lockb differ
diff --git a/dist/index.html b/dist/index.html
new file mode 100644
index 0000000..bb4d0db
--- /dev/null
+++ b/dist/index.html
@@ -0,0 +1,21 @@
+
+
+
+ Logger-JS
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
new file mode 100644
index 0000000..5cdf365
--- /dev/null
+++ b/dist/index.js
@@ -0,0 +1 @@
+var b=function(){const D=new Map;for(let[$,J]of Object.entries(z)){for(let[W,q]of Object.entries(J))z[W]={open:`\x1B[${q[0]}m`,close:`\x1B[${q[1]}m`},J[W]=z[W],D.set(q[0],q[1]);Object.defineProperty(z,$,{value:J,enumerable:!1})}return Object.defineProperty(z,"codes",{value:D,enumerable:!1}),z.color.close="\x1B[39m",z.bgColor.close="\x1B[49m",z.color.ansi=Y(),z.color.ansi256=T(),z.color.ansi16m=R(),z.bgColor.ansi=Y(10),z.bgColor.ansi256=T(10),z.bgColor.ansi16m=R(10),Object.defineProperties(z,{rgbToAnsi256:{value($,J,W){if($===J&&J===W){if($<8)return 16;if($>248)return 231;return Math.round(($-8)/247*24)+232}return 16+36*Math.round($/255*5)+6*Math.round(J/255*5)+Math.round(W/255*5)},enumerable:!1},hexToRgb:{value($){const J=/[a-f\d]{6}|[a-f\d]{3}/i.exec($.toString(16));if(!J)return[0,0,0];let[W]=J;if(W.length===3)W=[...W].map((K)=>K+K).join("");const q=Number.parseInt(W,16);return[q>>16&255,q>>8&255,q&255]},enumerable:!1},hexToAnsi256:{value:($)=>z.rgbToAnsi256(...z.hexToRgb($)),enumerable:!1},ansi256ToAnsi:{value($){if($<8)return 30+$;if($<16)return 90+($-8);let J,W,q;if($>=232)J=(($-232)*10+8)/255,W=J,q=J;else{$-=16;const M=$%36;J=Math.floor($/36)/5,W=Math.floor(M/6)/5,q=M%6/5}const K=Math.max(J,W,q)*2;if(K===0)return 30;let X=30+(Math.round(q)<<2|Math.round(W)<<1|Math.round(J));if(K===2)X+=60;return X},enumerable:!1},rgbToAnsi:{value:($,J,W)=>z.ansi256ToAnsi(z.rgbToAnsi256($,J,W)),enumerable:!1},hexToAnsi:{value:($)=>z.ansi256ToAnsi(z.hexToAnsi256($)),enumerable:!1}}),z};var Y=(D=0)=>($)=>`\x1B[${$+D}m`,T=(D=0)=>($)=>`\x1B[${38+D};5;${$}m`,R=(D=0)=>($,J,W)=>`\x1B[${38+D};2;${$};${J};${W}m`,z={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},d=Object.keys(z.modifier),k=Object.keys(z.color),L=Object.keys(z.bgColor),i=[...k,...L],v=b(),Q=v;var G=(()=>{if(navigator.userAgentData){const D=navigator.userAgentData.brands.find(({brand:$})=>$==="Chromium");if(D&&D.version>93)return 3}if(/\b(Chrome|Chromium)\//.test(navigator.userAgent))return 1;return 0})(),f=G!==0&&{level:G,hasBasic:!0,has256:G>=2,has16m:G>=3},x={stdout:f,stderr:f},C=x;function I(D,$,J){let W=D.indexOf($);if(W===-1)return D;const q=$.length;let K=0,X="";do X+=D.slice(K,W)+$+J,K=W+q,W=D.indexOf($,K);while(W!==-1);return X+=D.slice(K),X}function E(D,$,J,W){let q=0,K="";do{const X=D[W-1]==="\r";K+=D.slice(q,X?W-1:W)+$+(X?"\r\n":"\n")+J,q=W+1,W=D.indexOf("\n",q)}while(W!==-1);return K+=D.slice(q),K}var F=function(D){return u(D)};var{stdout:A,stderr:S}=C,P=Symbol("GENERATOR"),O=Symbol("STYLER"),j=Symbol("IS_EMPTY"),_=["ansi","ansi","ansi256","ansi16m"],B=Object.create(null),h=(D,$={})=>{if($.level&&!(Number.isInteger($.level)&&$.level>=0&&$.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const J=A?A.level:0;D.level=$.level===void 0?J:$.level};var u=(D)=>{const $=(...J)=>J.join(" ");return h($,D),Object.setPrototypeOf($,F.prototype),$};Object.setPrototypeOf(F.prototype,Function.prototype);for(let[D,$]of Object.entries(Q))B[D]={get(){const J=w(this,N($.open,$.close,this[O]),this[j]);return Object.defineProperty(this,D,{value:J}),J}};B.visible={get(){const D=w(this,this[O],!0);return Object.defineProperty(this,"visible",{value:D}),D}};var V=(D,$,J,...W)=>{if(D==="rgb"){if($==="ansi16m")return Q[J].ansi16m(...W);if($==="ansi256")return Q[J].ansi256(Q.rgbToAnsi256(...W));return Q[J].ansi(Q.rgbToAnsi(...W))}if(D==="hex")return V("rgb",$,J,...Q.hexToRgb(...W));return Q[J][D](...W)},c=["rgb","hex","ansi256"];for(let D of c){B[D]={get(){const{level:J}=this;return function(...W){const q=N(V(D,_[J],"color",...W),Q.color.close,this[O]);return w(this,q,this[j])}}};const $="bg"+D[0].toUpperCase()+D.slice(1);B[$]={get(){const{level:J}=this;return function(...W){const q=N(V(D,_[J],"bgColor",...W),Q.bgColor.close,this[O]);return w(this,q,this[j])}}}}var y=Object.defineProperties(()=>{},{...B,level:{enumerable:!0,get(){return this[P].level},set(D){this[P].level=D}}}),N=(D,$,J)=>{let W,q;if(J===void 0)W=D,q=$;else W=J.openAll+D,q=$+J.closeAll;return{open:D,close:$,openAll:W,closeAll:q,parent:J}},w=(D,$,J)=>{const W=(...q)=>p(W,q.length===1?""+q[0]:q.join(" "));return Object.setPrototypeOf(W,y),W[P]=D,W[O]=$,W[j]=J,W},p=(D,$)=>{if(D.level<=0||!$)return D[j]?"":$;let J=D[O];if(J===void 0)return $;const{openAll:W,closeAll:q}=J;if($.includes("\x1B"))while(J!==void 0)$=I($,J.close,J.open),J=J.parent;const K=$.indexOf("\n");if(K!==-1)$=E($,q,W,K);return W+$+q};Object.defineProperties(F.prototype,B);var m=F(),l=F({level:S?S.level:0});var H=m;class U{static NDJsonData="";static NDJson=!1;static level=2;static colors=!0;static levels={error:0,warn:1,info:2,http:3,verbose:4,debug:5,silly:6};static levelsRev={0:"ERROR",1:"WARN",2:"INFO",3:"HTTP",4:"VERBOSE",5:"DEBUG",6:"SILLY"};static parseMessage(D){if(typeof D==="undefined")return null;if(typeof D==="object")D=JSON.stringify(D);return D}static formatMessage(D,$){let J=this.levelsRev[$],W=(new Date()).toISOString().split(".")[0].replace("T"," ");if(this.colors)switch(W=H.gray(W),$){case 0:J=H.bold(H.red(J)),D=H.red(D);break;case 1:J=H.bold(H.yellow(J)),D=H.yellow(D);break;case 2:J=H.bold(H.cyan(J)),D=H.cyan(D);break;case 3:J=H.bold(H.blue(J)),D=H.blue(D);break;case 4:J=H.bold(H.blue(J)),D=H.blue(D);break;case 5:J=H.bold(H.gray(J)),D=H.gray(D);break;case 6:J=H.bold(H.gray(J)),D=H.gray(D);break}return`[${W}] ${J} ${D}`}static processMessage(D,$){if(this.level<$)return;if(D=this.parseMessage(D),D===null)return;if(this.NDJson)this.putNDJson(D,$);switch($){case 0:console.error(this.formatMessage(D,$));break;case 1:console.warn(this.formatMessage(D,$));break;default:console.info(this.formatMessage(D,$));break}}static error(D){this.processMessage(D,0)}static warn(D){this.processMessage(D,1)}static info(D){this.processMessage(D,2)}static http(D){this.processMessage(D,3)}static verbose(D){this.processMessage(D,4)}static debug(D){this.processMessage(D,5)}static silly(D){this.processMessage(D,6)}static putNDJson(D,$){let J=this.NDJsonData.length!==0?"\n":"";this.NDJsonData+=J+JSON.stringify({time:(new Date()).toISOString(),level:$,msg:D})}static getNDJson(){return this.NDJsonData??""}}var Z=document.getElementById("text");U.level=6;document.getElementById("btn-error")?.addEventListener("click",()=>{U.error(Z?.value)});document.getElementById("btn-warn")?.addEventListener("click",()=>{U.warn(Z?.value)});document.getElementById("btn-info")?.addEventListener("click",()=>{U.info(Z?.value)});document.getElementById("btn-http")?.addEventListener("click",()=>{U.http(Z?.value)});document.getElementById("btn-verbose")?.addEventListener("click",()=>{U.verbose(Z?.value)});document.getElementById("btn-debug")?.addEventListener("click",()=>{U.debug(Z?.value)});document.getElementById("btn-silly")?.addEventListener("click",()=>{U.silly(Z?.value)});
diff --git a/module/logger.d.ts b/module/logger.d.ts
index e96c271..c87ae70 100644
--- a/module/logger.d.ts
+++ b/module/logger.d.ts
@@ -1,100 +1,94 @@
/**
* Represents a logger utility for logging messages with different log levels.
- */
+*/
export default class Logger {
- static "__#1@#NDJson": string;
+ private static NDJsonData;
/**
* Indicates whether NDJson is enabled.
* @type {boolean}
- */
+ */
static NDJson: boolean;
/**
* The log level of the logger.
* @type {number}
- */
+ */
static level: number;
/**
* Indicates whether colors are enabled for log messages.
* @type {boolean}
- */
+ */
static colors: boolean;
/**
* Defines log levels and their associated numeric values.
- * @type {Object}
- */
- static levels: any;
- static "__#1@#levels": {
- 0: string;
- 1: string;
- 2: string;
- 3: string;
- 4: string;
- 5: string;
- 6: string;
- };
+ * @type {Record}
+ */
+ static readonly levels: Record;
+ private static readonly levelsRev;
/**
* Parses the log message to ensure it is a string.
* @param {*} message - The log message.
* @returns {string | null} - The parsed log message or null if the message is undefined.
- */
+ */
static parseMessage(message: any): string | null;
/**
* Formats the log message with timestamp and log level.
* @param {string} message - The log message.
* @param {number} logLevel - The log level.
* @returns {string} - The formatted log message.
- */
+ */
static formatMessage(message: string, logLevel: number): string;
/**
* Processes and logs a message with the specified log level.
* @param {*} message - The log message.
- * @param {number} level - The log level.
- */
- static "__#1@#processMessage"(message: any, level: number): void;
+ * @param {number} logLevel - The log level.
+ */
+ private static processMessage;
/**
* Logs an error message.
* @param {*} message - The error message.
- */
+ */
static error(message: any): void;
/**
* Logs a warning message.
* @param {*} message - The warning message.
- */
+ */
static warn(message: any): void;
/**
* Logs an informational message.
* @param {*} message - The informational message.
- */
+ */
static info(message: any): void;
/**
* Logs an HTTP-related message.
* @param {*} message - The HTTP-related message.
- */
+ */
static http(message: any): void;
/**
* Logs a verbose message.
* @param {*} message - The verbose message.
- */
+ */
static verbose(message: any): void;
/**
* Logs a debug message.
* @param {*} message - The debug message.
- */
+ */
static debug(message: any): void;
/**
* Logs a silly message.
* @param {*} message - The silly message.
- */
+ */
static silly(message: any): void;
/**
* Appends a message to NDJson format.
* @param {string} message - The message to append.
* @param {number} logLevel - The log level associated with the message.
- */
+ */
static putNDJson(message: string, logLevel: number): void;
/**
* Gets the NDJson log.
* @returns {string} - The NDJson log.
- */
+ */
static getNDJson(): string;
-}
\ No newline at end of file
+}
+
+export {};
diff --git a/module/logger.js b/module/logger.js
index 826f6a0..0edd5bb 100644
--- a/module/logger.js
+++ b/module/logger.js
@@ -1,103 +1,6 @@
-var __defProp = Object.defineProperty;
-var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
-var __publicField = (obj, key, value) => {
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
- return value;
-};
-var __accessCheck = (obj, member, msg) => {
- if (!member.has(obj))
- throw TypeError("Cannot " + msg);
-};
-var __privateGet = (obj, member, getter) => {
- __accessCheck(obj, member, "read from private field");
- return getter ? getter.call(obj) : member.get(obj);
-};
-var __privateAdd = (obj, member, value) => {
- if (member.has(obj))
- throw TypeError("Cannot add the same private member more than once");
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
-};
-var __privateSet = (obj, member, value, setter) => {
- __accessCheck(obj, member, "write to private field");
- setter ? setter.call(obj, value) : member.set(obj, value);
- return value;
-};
-var __privateMethod = (obj, member, method) => {
- __accessCheck(obj, member, "access private method");
- return method;
-};
-
// node_modules/chalk/source/vendor/ansi-styles/index.js
-var ANSI_BACKGROUND_OFFSET = 10;
-var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
-var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
-var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
-var styles = {
- modifier: {
- reset: [0, 0],
- // 21 isn't widely supported and 22 does the same thing
- bold: [1, 22],
- dim: [2, 22],
- italic: [3, 23],
- underline: [4, 24],
- overline: [53, 55],
- inverse: [7, 27],
- hidden: [8, 28],
- strikethrough: [9, 29]
- },
- color: {
- black: [30, 39],
- red: [31, 39],
- green: [32, 39],
- yellow: [33, 39],
- blue: [34, 39],
- magenta: [35, 39],
- cyan: [36, 39],
- white: [37, 39],
- // Bright color
- blackBright: [90, 39],
- gray: [90, 39],
- // Alias of `blackBright`
- grey: [90, 39],
- // Alias of `blackBright`
- redBright: [91, 39],
- greenBright: [92, 39],
- yellowBright: [93, 39],
- blueBright: [94, 39],
- magentaBright: [95, 39],
- cyanBright: [96, 39],
- whiteBright: [97, 39]
- },
- bgColor: {
- bgBlack: [40, 49],
- bgRed: [41, 49],
- bgGreen: [42, 49],
- bgYellow: [43, 49],
- bgBlue: [44, 49],
- bgMagenta: [45, 49],
- bgCyan: [46, 49],
- bgWhite: [47, 49],
- // Bright color
- bgBlackBright: [100, 49],
- bgGray: [100, 49],
- // Alias of `bgBlackBright`
- bgGrey: [100, 49],
- // Alias of `bgBlackBright`
- bgRedBright: [101, 49],
- bgGreenBright: [102, 49],
- bgYellowBright: [103, 49],
- bgBlueBright: [104, 49],
- bgMagentaBright: [105, 49],
- bgCyanBright: [106, 49],
- bgWhiteBright: [107, 49]
- }
-};
-var modifierNames = Object.keys(styles.modifier);
-var foregroundColorNames = Object.keys(styles.color);
-var backgroundColorNames = Object.keys(styles.bgColor);
-var colorNames = [...foregroundColorNames, ...backgroundColorNames];
-function assembleStyles() {
- const codes = /* @__PURE__ */ new Map();
+var assembleStyles = function() {
+ const codes = new Map;
for (const [groupName, group] of Object.entries(styles)) {
for (const [styleName, style] of Object.entries(group)) {
styles[styleName] = {
@@ -152,11 +55,9 @@ function assembleStyles() {
}
const integer = Number.parseInt(colorString, 16);
return [
- /* eslint-disable no-bitwise */
integer >> 16 & 255,
integer >> 8 & 255,
integer & 255
- /* eslint-enable no-bitwise */
];
},
enumerable: false
@@ -209,7 +110,68 @@ function assembleStyles() {
}
});
return styles;
-}
+};
+var ANSI_BACKGROUND_OFFSET = 10;
+var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
+var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
+var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
+var styles = {
+ modifier: {
+ reset: [0, 0],
+ bold: [1, 22],
+ dim: [2, 22],
+ italic: [3, 23],
+ underline: [4, 24],
+ overline: [53, 55],
+ inverse: [7, 27],
+ hidden: [8, 28],
+ strikethrough: [9, 29]
+ },
+ color: {
+ black: [30, 39],
+ red: [31, 39],
+ green: [32, 39],
+ yellow: [33, 39],
+ blue: [34, 39],
+ magenta: [35, 39],
+ cyan: [36, 39],
+ white: [37, 39],
+ blackBright: [90, 39],
+ gray: [90, 39],
+ grey: [90, 39],
+ redBright: [91, 39],
+ greenBright: [92, 39],
+ yellowBright: [93, 39],
+ blueBright: [94, 39],
+ magentaBright: [95, 39],
+ cyanBright: [96, 39],
+ whiteBright: [97, 39]
+ },
+ bgColor: {
+ bgBlack: [40, 49],
+ bgRed: [41, 49],
+ bgGreen: [42, 49],
+ bgYellow: [43, 49],
+ bgBlue: [44, 49],
+ bgMagenta: [45, 49],
+ bgCyan: [46, 49],
+ bgWhite: [47, 49],
+ bgBlackBright: [100, 49],
+ bgGray: [100, 49],
+ bgGrey: [100, 49],
+ bgRedBright: [101, 49],
+ bgGreenBright: [102, 49],
+ bgYellowBright: [103, 49],
+ bgBlueBright: [104, 49],
+ bgMagentaBright: [105, 49],
+ bgCyanBright: [106, 49],
+ bgWhiteBright: [107, 49]
+ }
+};
+var modifierNames = Object.keys(styles.modifier);
+var foregroundColorNames = Object.keys(styles.color);
+var backgroundColorNames = Object.keys(styles.bgColor);
+var colorNames = [...foregroundColorNames, ...backgroundColorNames];
var ansiStyles = assembleStyles();
var ansi_styles_default = ansiStyles;
@@ -269,6 +231,9 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
}
// node_modules/chalk/source/index.js
+var createChalk = function(options) {
+ return chalkFactory(options);
+};
var { stdout: stdoutColor, stderr: stderrColor } = browser_default;
var GENERATOR = Symbol("GENERATOR");
var STYLER = Symbol("STYLER");
@@ -279,23 +244,20 @@ var levelMapping = [
"ansi256",
"ansi16m"
];
-var styles2 = /* @__PURE__ */ Object.create(null);
+var styles2 = Object.create(null);
var applyOptions = (object, options = {}) => {
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
throw new Error("The `level` option should be an integer from 0 to 3");
}
const colorLevel = stdoutColor ? stdoutColor.level : 0;
- object.level = options.level === void 0 ? colorLevel : options.level;
+ object.level = options.level === undefined ? colorLevel : options.level;
};
var chalkFactory = (options) => {
- const chalk2 = (...strings) => strings.join(" ");
- applyOptions(chalk2, options);
- Object.setPrototypeOf(chalk2, createChalk.prototype);
- return chalk2;
+ const chalk = (...strings) => strings.join(" ");
+ applyOptions(chalk, options);
+ Object.setPrototypeOf(chalk, createChalk.prototype);
+ return chalk;
};
-function createChalk(options) {
- return chalkFactory(options);
-}
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
styles2[styleName] = {
@@ -366,7 +328,7 @@ var proto = Object.defineProperties(() => {
var createStyler = (open, close, parent) => {
let openAll;
let closeAll;
- if (parent === void 0) {
+ if (parent === undefined) {
openAll = open;
closeAll = close;
} else {
@@ -394,12 +356,12 @@ var applyStyle = (self, string) => {
return self[IS_EMPTY] ? "" : string;
}
let styler = self[STYLER];
- if (styler === void 0) {
+ if (styler === undefined) {
return string;
}
const { openAll, closeAll } = styler;
if (string.includes("\x1B")) {
- while (styler !== void 0) {
+ while (styler !== undefined) {
string = stringReplaceAll(string, styler.close, styler.open);
styler = styler.parent;
}
@@ -415,14 +377,30 @@ var chalk = createChalk();
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
var source_default = chalk;
-// module/logger.js
-var _NDJson, _levels, _processMessage, processMessage_fn;
-var Logger = class {
- /**
- * Parses the log message to ensure it is a string.
- * @param {*} message - The log message.
- * @returns {string | null} - The parsed log message or null if the message is undefined.
- */
+// src/logger.ts
+class Logger {
+ static NDJsonData = "";
+ static NDJson = false;
+ static level = 2;
+ static colors = true;
+ static levels = {
+ error: 0,
+ warn: 1,
+ info: 2,
+ http: 3,
+ verbose: 4,
+ debug: 5,
+ silly: 6
+ };
+ static levelsRev = {
+ 0: "ERROR",
+ 1: "WARN",
+ 2: "INFO",
+ 3: "HTTP",
+ 4: "VERBOSE",
+ 5: "DEBUG",
+ 6: "SILLY"
+ };
static parseMessage(message) {
if (typeof message === "undefined")
return null;
@@ -430,15 +408,9 @@ var Logger = class {
message = JSON.stringify(message);
return message;
}
- /**
- * Formats the log message with timestamp and log level.
- * @param {string} message - The log message.
- * @param {number} logLevel - The log level.
- * @returns {string} - The formatted log message.
- */
static formatMessage(message, logLevel) {
- let type = __privateGet(this, _levels)[logLevel];
- let date = (/* @__PURE__ */ new Date()).toISOString().split(".")[0].replace("T", " ");
+ let type = this.levelsRev[logLevel];
+ let date = new Date().toISOString().split(".")[0].replace("T", " ");
if (this.colors) {
date = source_default.gray(date);
switch (logLevel) {
@@ -474,139 +446,55 @@ var Logger = class {
}
return `[${date}] ${type} ${message}`;
}
- /**
- * Logs an error message.
- * @param {*} message - The error message.
- */
+ static processMessage(message, logLevel) {
+ if (this.level < logLevel)
+ return;
+ message = this.parseMessage(message);
+ if (message === null)
+ return;
+ if (this.NDJson)
+ this.putNDJson(message, logLevel);
+ switch (logLevel) {
+ case 0:
+ console.error(this.formatMessage(message, logLevel));
+ break;
+ case 1:
+ console.warn(this.formatMessage(message, logLevel));
+ break;
+ default:
+ console.info(this.formatMessage(message, logLevel));
+ break;
+ }
+ }
static error(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 0);
+ this.processMessage(message, 0);
}
- /**
- * Logs a warning message.
- * @param {*} message - The warning message.
- */
static warn(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 1);
+ this.processMessage(message, 1);
}
- /**
- * Logs an informational message.
- * @param {*} message - The informational message.
- */
static info(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 2);
+ this.processMessage(message, 2);
}
- /**
- * Logs an HTTP-related message.
- * @param {*} message - The HTTP-related message.
- */
static http(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 3);
+ this.processMessage(message, 3);
}
- /**
- * Logs a verbose message.
- * @param {*} message - The verbose message.
- */
static verbose(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 4);
+ this.processMessage(message, 4);
}
- /**
- * Logs a debug message.
- * @param {*} message - The debug message.
- */
static debug(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 5);
+ this.processMessage(message, 5);
}
- /**
- * Logs a silly message.
- * @param {*} message - The silly message.
- */
static silly(message) {
- __privateMethod(this, _processMessage, processMessage_fn).call(this, message, 6);
+ this.processMessage(message, 6);
}
- /**
- * Appends a message to NDJson format.
- * @param {string} message - The message to append.
- * @param {number} logLevel - The log level associated with the message.
- */
static putNDJson(message, logLevel) {
- let separator = __privateGet(this, _NDJson).length !== 0 ? "\n" : "";
- __privateSet(this, _NDJson, __privateGet(this, _NDJson) + (separator + JSON.stringify({ "time": (/* @__PURE__ */ new Date()).toISOString(), "level": logLevel, "msg": message })));
+ let separator = this.NDJsonData.length !== 0 ? "\n" : "";
+ this.NDJsonData += separator + JSON.stringify({ time: new Date().toISOString(), level: logLevel, msg: message });
}
- /**
- * Gets the NDJson log.
- * @returns {string} - The NDJson log.
- */
static getNDJson() {
- return __privateGet(this, _NDJson);
- }
-};
-_NDJson = new WeakMap();
-_levels = new WeakMap();
-_processMessage = new WeakSet();
-processMessage_fn = function(message, level2) {
- if (this.level < level2)
- return;
- message = this.parseMessage(message);
- if (message === null)
- return;
- if (this.NDJson)
- this.putNDJson(message, level2);
- switch (level2) {
- case 0:
- console.error(this.formatMessage(message, level2));
- break;
- case 1:
- console.warn(this.formatMessage(message, level2));
- break;
- default:
- console.info(this.formatMessage(message, level2));
- break;
+ return this.NDJsonData ?? "";
}
-};
-/**
- * Processes and logs a message with the specified log level.
- * @param {*} message - The log message.
- * @param {number} level - The log level.
- */
-__privateAdd(Logger, _processMessage);
-__privateAdd(Logger, _NDJson, "");
-/**
- * Indicates whether NDJson is enabled.
- * @type {boolean}
- */
-__publicField(Logger, "NDJson", false);
-/**
- * The log level of the logger.
- * @type {number}
- */
-__publicField(Logger, "level", 2);
-/**
- * Indicates whether colors are enabled for log messages.
- * @type {boolean}
- */
-__publicField(Logger, "colors", true);
-/**
- * Defines log levels and their associated numeric values.
- * @type {Object}
- */
-__publicField(Logger, "levels", {
- error: 0,
- warn: 1,
- info: 2,
- http: 3,
- verbose: 4,
- debug: 5,
- silly: 6
-});
-__privateAdd(Logger, _levels, {
- 0: "ERROR",
- 1: "WARN",
- 2: "INFO",
- 3: "HTTP",
- 4: "VERBOSE",
- 5: "DEBUG",
- 6: "SILLY"
-});
+}
export {
Logger as default
};
diff --git a/package-lock.json b/package-lock.json
deleted file mode 100644
index c37d258..0000000
--- a/package-lock.json
+++ /dev/null
@@ -1,772 +0,0 @@
-{
- "name": "@rabbit-company/logger",
- "version": "2.1.1",
- "lockfileVersion": 3,
- "requires": true,
- "packages": {
- "": {
- "name": "@rabbit-company/logger",
- "version": "2.1.1",
- "license": "MIT",
- "dependencies": {
- "chalk": "^5.3.0"
- },
- "devDependencies": {
- "@rabbit-company/rabbit-builder": "^1.0.5"
- },
- "funding": {
- "url": "https://rabbit-company.com/donation"
- }
- },
- "node_modules/@esbuild/android-arm": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.14.tgz",
- "integrity": "sha512-0CnlwnjDU8cks0yJLXfkaU/uoLyRf9VZJs4p1PskBr2AlAHeEsFEwJEo0of/Z3g+ilw5mpyDwThlxzNEIxOE4g==",
- "cpu": [
- "arm"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/android-arm64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.14.tgz",
- "integrity": "sha512-eLOpPO1RvtsP71afiFTvS7tVFShJBCT0txiv/xjFBo5a7R7Gjw7X0IgIaFoLKhqXYAXhahoXm7qAmRXhY4guJg==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/android-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.14.tgz",
- "integrity": "sha512-nrfQYWBfLGfSGLvRVlt6xi63B5IbfHm3tZCdu/82zuFPQ7zez4XjmRtF/wIRYbJQ/DsZrxJdEvYFE67avYXyng==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/darwin-arm64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.14.tgz",
- "integrity": "sha512-eoSjEuDsU1ROwgBH/c+fZzuSyJUVXQTOIN9xuLs9dE/9HbV/A5IqdXHU1p2OfIMwBwOYJ9SFVGGldxeRCUJFyw==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/darwin-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.14.tgz",
- "integrity": "sha512-zN0U8RWfrDttdFNkHqFYZtOH8hdi22z0pFm0aIJPsNC4QQZv7je8DWCX5iA4Zx6tRhS0CCc0XC2m7wKsbWEo5g==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/freebsd-arm64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.14.tgz",
- "integrity": "sha512-z0VcD4ibeZWVQCW1O7szaLxGsx54gcCnajEJMdYoYjLiq4g1jrP2lMq6pk71dbS5+7op/L2Aod+erw+EUr28/A==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "freebsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/freebsd-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.14.tgz",
- "integrity": "sha512-hd9mPcxfTgJlolrPlcXkQk9BMwNBvNBsVaUe5eNUqXut6weDQH8whcNaKNF2RO8NbpT6GY8rHOK2A9y++s+ehw==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "freebsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-arm": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.14.tgz",
- "integrity": "sha512-BNTl+wSJ1omsH8s3TkQmIIIQHwvwJrU9u1ggb9XU2KTVM4TmthRIVyxSp2qxROJHhZuW/r8fht46/QE8hU8Qvg==",
- "cpu": [
- "arm"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-arm64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.14.tgz",
- "integrity": "sha512-FhAMNYOq3Iblcj9i+K0l1Fp/MHt+zBeRu/Qkf0LtrcFu3T45jcwB6A1iMsemQ42vR3GBhjNZJZTaCe3VFPbn9g==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-ia32": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.14.tgz",
- "integrity": "sha512-91OK/lQ5y2v7AsmnFT+0EyxdPTNhov3y2CWMdizyMfxSxRqHazXdzgBKtlmkU2KYIc+9ZK3Vwp2KyXogEATYxQ==",
- "cpu": [
- "ia32"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-loong64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.14.tgz",
- "integrity": "sha512-vp15H+5NR6hubNgMluqqKza85HcGJgq7t6rMH7O3Y6ApiOWPkvW2AJfNojUQimfTp6OUrACUXfR4hmpcENXoMQ==",
- "cpu": [
- "loong64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-mips64el": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.14.tgz",
- "integrity": "sha512-90TOdFV7N+fgi6c2+GO9ochEkmm9kBAKnuD5e08GQMgMINOdOFHuYLPQ91RYVrnWwQ5683sJKuLi9l4SsbJ7Hg==",
- "cpu": [
- "mips64el"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-ppc64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.14.tgz",
- "integrity": "sha512-NnBGeoqKkTugpBOBZZoktQQ1Yqb7aHKmHxsw43NddPB2YWLAlpb7THZIzsRsTr0Xw3nqiPxbA1H31ZMOG+VVPQ==",
- "cpu": [
- "ppc64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-riscv64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.14.tgz",
- "integrity": "sha512-0qdlKScLXA8MGVy21JUKvMzCYWovctuP8KKqhtE5A6IVPq4onxXhSuhwDd2g5sRCzNDlDjitc5sX31BzDoL5Fw==",
- "cpu": [
- "riscv64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-s390x": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.14.tgz",
- "integrity": "sha512-Hdm2Jo1yaaOro4v3+6/zJk6ygCqIZuSDJHdHaf8nVH/tfOuoEX5Riv03Ka15LmQBYJObUTNS1UdyoMk0WUn9Ww==",
- "cpu": [
- "s390x"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.14.tgz",
- "integrity": "sha512-8KHF17OstlK4DuzeF/KmSgzrTWQrkWj5boluiiq7kvJCiQVzUrmSkaBvcLB2UgHpKENO2i6BthPkmUhNDaJsVw==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/netbsd-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.14.tgz",
- "integrity": "sha512-nVwpqvb3yyXztxIT2+VsxJhB5GCgzPdk1n0HHSnchRAcxqKO6ghXwHhJnr0j/B+5FSyEqSxF4q03rbA2fKXtUQ==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "netbsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/openbsd-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.14.tgz",
- "integrity": "sha512-1RZ7uQQ9zcy/GSAJL1xPdN7NDdOOtNEGiJalg/MOzeakZeTrgH/DoCkbq7TaPDiPhWqnDF+4bnydxRqQD7il6g==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "openbsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/sunos-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.14.tgz",
- "integrity": "sha512-nqMjDsFwv7vp7msrwWRysnM38Sd44PKmW8EzV01YzDBTcTWUpczQg6mGao9VLicXSgW/iookNK6AxeogNVNDZA==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "sunos"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-arm64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.14.tgz",
- "integrity": "sha512-xrD0mccTKRBBIotrITV7WVQAwNJ5+1va6L0H9zN92v2yEdjfAN7864cUaZwJS7JPEs53bDTzKFbfqVlG2HhyKQ==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-ia32": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.14.tgz",
- "integrity": "sha512-nXpkz9bbJrLLyUTYtRotSS3t5b+FOuljg8LgLdINWFs3FfqZMtbnBCZFUmBzQPyxqU87F8Av+3Nco/M3hEcu1w==",
- "cpu": [
- "ia32"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-x64": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.14.tgz",
- "integrity": "sha512-gPQmsi2DKTaEgG14hc3CHXHp62k8g6qr0Pas+I4lUxRMugGSATh/Bi8Dgusoz9IQ0IfdrvLpco6kujEIBoaogA==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@rabbit-company/rabbit-builder": {
- "version": "1.0.5",
- "resolved": "https://registry.npmjs.org/@rabbit-company/rabbit-builder/-/rabbit-builder-1.0.5.tgz",
- "integrity": "sha512-lbsQX1ouSX/OzfMHbyyj4gvm8by5myxB3oNVMQywpNDj69jTxzg0t5zu2xdIDNWYmAdcDrzd7YZVMbaF1tJ+6A==",
- "dev": true,
- "dependencies": {
- "chalk": "^5.2.0",
- "clean-css": "^5.3.2",
- "esbuild": "^0.17.11",
- "fs-extra": "^11.1.0",
- "glob": "^9.2.1",
- "html-minifier": "^4.0.0",
- "multi-progress-bars": "^5.0.3"
- },
- "bin": {
- "rabbit-builder": "bin/index.mjs"
- },
- "funding": {
- "url": "https://rabbit-company.com/donation"
- }
- },
- "node_modules/ansi-regex": {
- "version": "6.0.1",
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz",
- "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==",
- "dev": true,
- "engines": {
- "node": ">=12"
- },
- "funding": {
- "url": "https://github.com/chalk/ansi-regex?sponsor=1"
- }
- },
- "node_modules/balanced-match": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
- "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
- "dev": true
- },
- "node_modules/brace-expansion": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
- "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
- "dev": true,
- "dependencies": {
- "balanced-match": "^1.0.0"
- }
- },
- "node_modules/camel-case": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz",
- "integrity": "sha512-+MbKztAYHXPr1jNTSKQF52VpcFjwY5RkR7fxksV8Doo4KAYc5Fl4UJRgthBbTmEx8C54DqahhbLJkDwjI3PI/w==",
- "dev": true,
- "dependencies": {
- "no-case": "^2.2.0",
- "upper-case": "^1.1.1"
- }
- },
- "node_modules/chalk": {
- "version": "5.3.0",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
- "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
- "engines": {
- "node": "^12.17.0 || ^14.13 || >=16.0.0"
- },
- "funding": {
- "url": "https://github.com/chalk/chalk?sponsor=1"
- }
- },
- "node_modules/clean-css": {
- "version": "5.3.2",
- "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-5.3.2.tgz",
- "integrity": "sha512-JVJbM+f3d3Q704rF4bqQ5UUyTtuJ0JRKNbTKVEeujCCBoMdkEi+V+e8oktO9qGQNSvHrFTM6JZRXrUvGR1czww==",
- "dev": true,
- "dependencies": {
- "source-map": "~0.6.0"
- },
- "engines": {
- "node": ">= 10.0"
- }
- },
- "node_modules/commander": {
- "version": "2.20.3",
- "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
- "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
- "dev": true
- },
- "node_modules/eastasianwidth": {
- "version": "0.2.0",
- "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
- "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
- "dev": true
- },
- "node_modules/emoji-regex": {
- "version": "9.2.2",
- "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
- "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
- "dev": true
- },
- "node_modules/esbuild": {
- "version": "0.17.14",
- "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.14.tgz",
- "integrity": "sha512-vOO5XhmVj/1XQR9NQ1UPq6qvMYL7QFJU57J5fKBKBKxp17uDt5PgxFDb4A2nEiXhr1qQs4x0F5+66hVVw4ruNw==",
- "dev": true,
- "hasInstallScript": true,
- "bin": {
- "esbuild": "bin/esbuild"
- },
- "engines": {
- "node": ">=12"
- },
- "optionalDependencies": {
- "@esbuild/android-arm": "0.17.14",
- "@esbuild/android-arm64": "0.17.14",
- "@esbuild/android-x64": "0.17.14",
- "@esbuild/darwin-arm64": "0.17.14",
- "@esbuild/darwin-x64": "0.17.14",
- "@esbuild/freebsd-arm64": "0.17.14",
- "@esbuild/freebsd-x64": "0.17.14",
- "@esbuild/linux-arm": "0.17.14",
- "@esbuild/linux-arm64": "0.17.14",
- "@esbuild/linux-ia32": "0.17.14",
- "@esbuild/linux-loong64": "0.17.14",
- "@esbuild/linux-mips64el": "0.17.14",
- "@esbuild/linux-ppc64": "0.17.14",
- "@esbuild/linux-riscv64": "0.17.14",
- "@esbuild/linux-s390x": "0.17.14",
- "@esbuild/linux-x64": "0.17.14",
- "@esbuild/netbsd-x64": "0.17.14",
- "@esbuild/openbsd-x64": "0.17.14",
- "@esbuild/sunos-x64": "0.17.14",
- "@esbuild/win32-arm64": "0.17.14",
- "@esbuild/win32-ia32": "0.17.14",
- "@esbuild/win32-x64": "0.17.14"
- }
- },
- "node_modules/fs-extra": {
- "version": "11.1.1",
- "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
- "integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
- "dev": true,
- "dependencies": {
- "graceful-fs": "^4.2.0",
- "jsonfile": "^6.0.1",
- "universalify": "^2.0.0"
- },
- "engines": {
- "node": ">=14.14"
- }
- },
- "node_modules/fs.realpath": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
- "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
- "dev": true
- },
- "node_modules/glob": {
- "version": "9.3.2",
- "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.2.tgz",
- "integrity": "sha512-BTv/JhKXFEHsErMte/AnfiSv8yYOLLiyH2lTg8vn02O21zWFgHPTfxtgn1QRe7NRgggUhC8hacR2Re94svHqeA==",
- "dev": true,
- "dependencies": {
- "fs.realpath": "^1.0.0",
- "minimatch": "^7.4.1",
- "minipass": "^4.2.4",
- "path-scurry": "^1.6.1"
- },
- "engines": {
- "node": ">=16 || 14 >=14.17"
- },
- "funding": {
- "url": "https://github.com/sponsors/isaacs"
- }
- },
- "node_modules/graceful-fs": {
- "version": "4.2.11",
- "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
- "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
- "dev": true
- },
- "node_modules/he": {
- "version": "1.2.0",
- "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
- "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
- "dev": true,
- "bin": {
- "he": "bin/he"
- }
- },
- "node_modules/html-minifier": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/html-minifier/-/html-minifier-4.0.0.tgz",
- "integrity": "sha512-aoGxanpFPLg7MkIl/DDFYtb0iWz7jMFGqFhvEDZga6/4QTjneiD8I/NXL1x5aaoCp7FSIT6h/OhykDdPsbtMig==",
- "dev": true,
- "dependencies": {
- "camel-case": "^3.0.0",
- "clean-css": "^4.2.1",
- "commander": "^2.19.0",
- "he": "^1.2.0",
- "param-case": "^2.1.1",
- "relateurl": "^0.2.7",
- "uglify-js": "^3.5.1"
- },
- "bin": {
- "html-minifier": "cli.js"
- },
- "engines": {
- "node": ">=6"
- }
- },
- "node_modules/html-minifier/node_modules/clean-css": {
- "version": "4.2.4",
- "resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.4.tgz",
- "integrity": "sha512-EJUDT7nDVFDvaQgAo2G/PJvxmp1o/c6iXLbswsBbUFXi1Nr+AjA2cKmfbKDMjMvzEe75g3P6JkaDDAKk96A85A==",
- "dev": true,
- "dependencies": {
- "source-map": "~0.6.0"
- },
- "engines": {
- "node": ">= 4.0"
- }
- },
- "node_modules/jsonfile": {
- "version": "6.1.0",
- "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
- "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
- "dev": true,
- "dependencies": {
- "universalify": "^2.0.0"
- },
- "optionalDependencies": {
- "graceful-fs": "^4.1.6"
- }
- },
- "node_modules/lower-case": {
- "version": "1.1.4",
- "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz",
- "integrity": "sha512-2Fgx1Ycm599x+WGpIYwJOvsjmXFzTSc34IwDWALRA/8AopUKAVPwfJ+h5+f85BCp0PWmmJcWzEpxOpoXycMpdA==",
- "dev": true
- },
- "node_modules/lru-cache": {
- "version": "7.18.3",
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",
- "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==",
- "dev": true,
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/minimatch": {
- "version": "7.4.3",
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.3.tgz",
- "integrity": "sha512-5UB4yYusDtkRPbRiy1cqZ1IpGNcJCGlEMG17RKzPddpyiPKoCdwohbED8g4QXT0ewCt8LTkQXuljsUfQ3FKM4A==",
- "dev": true,
- "dependencies": {
- "brace-expansion": "^2.0.1"
- },
- "engines": {
- "node": ">=10"
- },
- "funding": {
- "url": "https://github.com/sponsors/isaacs"
- }
- },
- "node_modules/minipass": {
- "version": "4.2.5",
- "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz",
- "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==",
- "dev": true,
- "engines": {
- "node": ">=8"
- }
- },
- "node_modules/multi-progress-bars": {
- "version": "5.0.3",
- "resolved": "https://registry.npmjs.org/multi-progress-bars/-/multi-progress-bars-5.0.3.tgz",
- "integrity": "sha512-/EzDF3NVeYTFLoLQ33fgvM6933rS2MZlEPWBivsc94Y/lj2xpWOs/DpJrCG+XrPOo4/P6DW+oxZyKnRKw0d/nQ==",
- "dev": true,
- "dependencies": {
- "chalk": "^5.2.0",
- "string-width": "5.1.2",
- "strip-ansi": "7.0.1"
- },
- "engines": {
- "node": ">14.18.0"
- }
- },
- "node_modules/no-case": {
- "version": "2.3.2",
- "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz",
- "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==",
- "dev": true,
- "dependencies": {
- "lower-case": "^1.1.1"
- }
- },
- "node_modules/param-case": {
- "version": "2.1.1",
- "resolved": "https://registry.npmjs.org/param-case/-/param-case-2.1.1.tgz",
- "integrity": "sha512-eQE845L6ot89sk2N8liD8HAuH4ca6Vvr7VWAWwt7+kvvG5aBcPmmphQ68JsEG2qa9n1TykS2DLeMt363AAH8/w==",
- "dev": true,
- "dependencies": {
- "no-case": "^2.2.0"
- }
- },
- "node_modules/path-scurry": {
- "version": "1.6.3",
- "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.6.3.tgz",
- "integrity": "sha512-RAmB+n30SlN+HnNx6EbcpoDy9nwdpcGPnEKrJnu6GZoDWBdIjo1UQMVtW2ybtC7LC2oKLcMq8y5g8WnKLiod9g==",
- "dev": true,
- "dependencies": {
- "lru-cache": "^7.14.1",
- "minipass": "^4.0.2"
- },
- "engines": {
- "node": ">=16 || 14 >=14.17"
- },
- "funding": {
- "url": "https://github.com/sponsors/isaacs"
- }
- },
- "node_modules/relateurl": {
- "version": "0.2.7",
- "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz",
- "integrity": "sha512-G08Dxvm4iDN3MLM0EsP62EDV9IuhXPR6blNz6Utcp7zyV3tr4HVNINt6MpaRWbxoOHT3Q7YN2P+jaHX8vUbgog==",
- "dev": true,
- "engines": {
- "node": ">= 0.10"
- }
- },
- "node_modules/source-map": {
- "version": "0.6.1",
- "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
- "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
- "dev": true,
- "engines": {
- "node": ">=0.10.0"
- }
- },
- "node_modules/string-width": {
- "version": "5.1.2",
- "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
- "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
- "dev": true,
- "dependencies": {
- "eastasianwidth": "^0.2.0",
- "emoji-regex": "^9.2.2",
- "strip-ansi": "^7.0.1"
- },
- "engines": {
- "node": ">=12"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
- }
- },
- "node_modules/strip-ansi": {
- "version": "7.0.1",
- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.0.1.tgz",
- "integrity": "sha512-cXNxvT8dFNRVfhVME3JAe98mkXDYN2O1l7jmcwMnOslDeESg1rF/OZMtK0nRAhiari1unG5cD4jG3rapUAkLbw==",
- "dev": true,
- "dependencies": {
- "ansi-regex": "^6.0.1"
- },
- "engines": {
- "node": ">=12"
- },
- "funding": {
- "url": "https://github.com/chalk/strip-ansi?sponsor=1"
- }
- },
- "node_modules/uglify-js": {
- "version": "3.17.4",
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz",
- "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==",
- "dev": true,
- "bin": {
- "uglifyjs": "bin/uglifyjs"
- },
- "engines": {
- "node": ">=0.8.0"
- }
- },
- "node_modules/universalify": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
- "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
- "dev": true,
- "engines": {
- "node": ">= 10.0.0"
- }
- },
- "node_modules/upper-case": {
- "version": "1.1.3",
- "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz",
- "integrity": "sha512-WRbjgmYzgXkCV7zNVpy5YgrHgbBv126rMALQQMrmzOVC4GM2waQ9x7xtm8VU+1yF2kWyPzI9zbZ48n4vSxwfSA==",
- "dev": true
- }
- }
-}
diff --git a/package.json b/package.json
index 09fa7d1..920e524 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
"name": "@rabbit-company/logger",
- "version": "2.1.1",
+ "version": "3.0.0",
"description": "Simple logger",
- "main": "./src/logger.js",
+ "main": "./module/logger.js",
"browser": "./module/logger.js",
"type": "module",
"homepage": "https://github.com/Rabbit-Company/Logger-JS",
@@ -11,13 +11,11 @@
"license": "MIT",
"private": false,
"scripts": {
- "build": "rabbit-builder"
+ "build": "bun run build.ts"
},
"files": [
"module/logger.js",
- "module/logger.d.ts",
- "src/logger.js",
- "src/logger.d.ts"
+ "module/logger.d.ts"
],
"repository": {
"type": "git",
@@ -33,10 +31,13 @@
"keywords": [
"logger"
],
- "devDependencies": {
- "@rabbit-company/rabbit-builder": "^1.0.5"
- },
- "dependencies": {
+ "devDependencies": {
+ "@types/bun": "latest",
+ "bun-plugin-dts": "^0.2.1",
+ "@rabbit-company/logger": "^2.1.1",
"chalk": "^5.3.0"
- }
+ },
+ "peerDependencies": {
+ "typescript": "^5.0.0"
+ }
}
diff --git a/rabbit-builder.json b/rabbit-builder.json
deleted file mode 100644
index 8a5fbed..0000000
--- a/rabbit-builder.json
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "code": {
- "location": "src"
- },
- "tasks": {
- "dist": {
- "location": "dist",
- "output": ".",
- "execute": {
- "copy": {
- "action": "copy",
- "location": "../src"
- },
- "minifyHTML": {
- "action": "minifyHTML"
- },
- "minifyJS": {
- "action": "minifyJS",
- "sourceMap": "linked",
- "bundle": {}
- }
- }
- },
- "module": {
- "location": "module",
- "output": ".",
- "execute": {
- "copy": {
- "action": "copy",
- "location": "../src",
- "excludes": ["/index.html", "/index.js"]
- },
- "minifyJS": {
- "action": "minifyJS",
- "bundle": {
- "format": "esm",
- "minify": false
- }
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/index.js b/src/index.js
deleted file mode 100644
index 277a9bc..0000000
--- a/src/index.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import Logger from "./logger.js";
-
-// Enable all log levels
-Logger.level = 6;
-
-document.getElementById('btn-error').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.error(message);
-});
-
-document.getElementById('btn-warn').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.warn(message);
-});
-
-document.getElementById('btn-info').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.info(message);
-});
-
-document.getElementById('btn-http').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.http(message);
-});
-
-document.getElementById('btn-verbose').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.verbose(message);
-});
-
-document.getElementById('btn-debug').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.debug(message);
-});
-
-document.getElementById('btn-silly').addEventListener('click', () => {
- let message = document.getElementById('text').value;
- Logger.silly(message);
-});
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
new file mode 100644
index 0000000..1161c25
--- /dev/null
+++ b/src/index.ts
@@ -0,0 +1,34 @@
+import Logger from "./logger.js";
+
+const messageInput = document.getElementById('text') as HTMLInputElement;
+
+// Enable all log levels
+Logger.level = 6;
+
+document.getElementById('btn-error')?.addEventListener('click', () => {
+ Logger.error(messageInput?.value);
+});
+
+document.getElementById('btn-warn')?.addEventListener('click', () => {
+ Logger.warn(messageInput?.value);
+});
+
+document.getElementById('btn-info')?.addEventListener('click', () => {
+ Logger.info(messageInput?.value);
+});
+
+document.getElementById('btn-http')?.addEventListener('click', () => {
+ Logger.http(messageInput?.value);
+});
+
+document.getElementById('btn-verbose')?.addEventListener('click', () => {
+ Logger.verbose(messageInput?.value);
+});
+
+document.getElementById('btn-debug')?.addEventListener('click', () => {
+ Logger.debug(messageInput?.value);
+});
+
+document.getElementById('btn-silly')?.addEventListener('click', () => {
+ Logger.silly(messageInput?.value);
+});
\ No newline at end of file
diff --git a/src/logger.d.ts b/src/logger.d.ts
deleted file mode 100644
index e96c271..0000000
--- a/src/logger.d.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Represents a logger utility for logging messages with different log levels.
- */
-export default class Logger {
- static "__#1@#NDJson": string;
- /**
- * Indicates whether NDJson is enabled.
- * @type {boolean}
- */
- static NDJson: boolean;
- /**
- * The log level of the logger.
- * @type {number}
- */
- static level: number;
- /**
- * Indicates whether colors are enabled for log messages.
- * @type {boolean}
- */
- static colors: boolean;
- /**
- * Defines log levels and their associated numeric values.
- * @type {Object}
- */
- static levels: any;
- static "__#1@#levels": {
- 0: string;
- 1: string;
- 2: string;
- 3: string;
- 4: string;
- 5: string;
- 6: string;
- };
- /**
- * Parses the log message to ensure it is a string.
- * @param {*} message - The log message.
- * @returns {string | null} - The parsed log message or null if the message is undefined.
- */
- static parseMessage(message: any): string | null;
- /**
- * Formats the log message with timestamp and log level.
- * @param {string} message - The log message.
- * @param {number} logLevel - The log level.
- * @returns {string} - The formatted log message.
- */
- static formatMessage(message: string, logLevel: number): string;
- /**
- * Processes and logs a message with the specified log level.
- * @param {*} message - The log message.
- * @param {number} level - The log level.
- */
- static "__#1@#processMessage"(message: any, level: number): void;
- /**
- * Logs an error message.
- * @param {*} message - The error message.
- */
- static error(message: any): void;
- /**
- * Logs a warning message.
- * @param {*} message - The warning message.
- */
- static warn(message: any): void;
- /**
- * Logs an informational message.
- * @param {*} message - The informational message.
- */
- static info(message: any): void;
- /**
- * Logs an HTTP-related message.
- * @param {*} message - The HTTP-related message.
- */
- static http(message: any): void;
- /**
- * Logs a verbose message.
- * @param {*} message - The verbose message.
- */
- static verbose(message: any): void;
- /**
- * Logs a debug message.
- * @param {*} message - The debug message.
- */
- static debug(message: any): void;
- /**
- * Logs a silly message.
- * @param {*} message - The silly message.
- */
- static silly(message: any): void;
- /**
- * Appends a message to NDJson format.
- * @param {string} message - The message to append.
- * @param {number} logLevel - The log level associated with the message.
- */
- static putNDJson(message: string, logLevel: number): void;
- /**
- * Gets the NDJson log.
- * @returns {string} - The NDJson log.
- */
- static getNDJson(): string;
-}
\ No newline at end of file
diff --git a/src/logger.js b/src/logger.ts
similarity index 65%
rename from src/logger.js
rename to src/logger.ts
index eda0445..ea02349 100644
--- a/src/logger.js
+++ b/src/logger.ts
@@ -2,34 +2,34 @@ import chalk from 'chalk';
/**
* Represents a logger utility for logging messages with different log levels.
- */
+*/
export default class Logger{
- static #NDJson = '';
+ private static NDJsonData: string = '';
/**
* Indicates whether NDJson is enabled.
* @type {boolean}
- */
- static NDJson = false;
+ */
+ static NDJson: boolean = false;
/**
* The log level of the logger.
* @type {number}
- */
- static level = 2;
+ */
+ static level: number = 2;
/**
* Indicates whether colors are enabled for log messages.
* @type {boolean}
- */
- static colors = true;
+ */
+ static colors: boolean = true;
/**
* Defines log levels and their associated numeric values.
- * @type {Object}
- */
- static levels = {
+ * @type {Record}
+ */
+ static readonly levels: Record = {
error: 0,
warn: 1,
info: 2,
@@ -39,7 +39,7 @@ export default class Logger{
silly: 6
}
- static #levels = {
+ private static readonly levelsRev: Record = {
0: 'ERROR',
1: 'WARN',
2: 'INFO',
@@ -53,8 +53,8 @@ export default class Logger{
* Parses the log message to ensure it is a string.
* @param {*} message - The log message.
* @returns {string | null} - The parsed log message or null if the message is undefined.
- */
- static parseMessage(message){
+ */
+ static parseMessage(message: any): string | null{
if(typeof(message) === 'undefined') return null;
if(typeof(message) === 'object') message = JSON.stringify(message);
return message;
@@ -65,9 +65,9 @@ export default class Logger{
* @param {string} message - The log message.
* @param {number} logLevel - The log level.
* @returns {string} - The formatted log message.
- */
- static formatMessage(message, logLevel){
- let type = this.#levels[logLevel];
+ */
+ static formatMessage(message: string, logLevel: number): string{
+ let type = this.levelsRev[logLevel];
let date = new Date().toISOString().split('.')[0].replace('T', ' ');
if(this.colors){
@@ -111,23 +111,23 @@ export default class Logger{
/**
* Processes and logs a message with the specified log level.
* @param {*} message - The log message.
- * @param {number} level - The log level.
- */
- static #processMessage(message, level){
- if(this.level < level) return;
+ * @param {number} logLevel - The log level.
+ */
+ private static processMessage(message: any, logLevel: number): void{
+ if(this.level < logLevel) return;
message = this.parseMessage(message);
if(message === null) return;
- if(this.NDJson) this.putNDJson(message, level);
+ if(this.NDJson) this.putNDJson(message, logLevel);
- switch(level){
+ switch(logLevel){
case 0:
- console.error(this.formatMessage(message, level));
+ console.error(this.formatMessage(message, logLevel));
break;
case 1:
- console.warn(this.formatMessage(message, level));
+ console.warn(this.formatMessage(message, logLevel));
break;
default:
- console.info(this.formatMessage(message, level));
+ console.info(this.formatMessage(message, logLevel));
break;
}
}
@@ -136,75 +136,75 @@ export default class Logger{
/**
* Logs an error message.
* @param {*} message - The error message.
- */
- static error(message){
- this.#processMessage(message, 0);
+ */
+ static error(message: any): void{
+ this.processMessage(message, 0);
}
/**
* Logs a warning message.
* @param {*} message - The warning message.
- */
- static warn(message){
- this.#processMessage(message, 1);
+ */
+ static warn(message: any): void{
+ this.processMessage(message, 1);
}
/**
* Logs an informational message.
* @param {*} message - The informational message.
- */
- static info(message){
- this.#processMessage(message, 2);
+ */
+ static info(message: any): void{
+ this.processMessage(message, 2);
}
/**
* Logs an HTTP-related message.
* @param {*} message - The HTTP-related message.
- */
- static http(message){
- this.#processMessage(message, 3);
+ */
+ static http(message: any): void{
+ this.processMessage(message, 3);
}
/**
* Logs a verbose message.
* @param {*} message - The verbose message.
- */
- static verbose(message){
- this.#processMessage(message, 4);
+ */
+ static verbose(message: any): void{
+ this.processMessage(message, 4);
}
/**
* Logs a debug message.
* @param {*} message - The debug message.
- */
- static debug(message){
- this.#processMessage(message, 5);
+ */
+ static debug(message: any): void{
+ this.processMessage(message, 5);
}
/**
* Logs a silly message.
* @param {*} message - The silly message.
- */
- static silly(message){
- this.#processMessage(message, 6);
+ */
+ static silly(message: any): void{
+ this.processMessage(message, 6);
}
/**
* Appends a message to NDJson format.
* @param {string} message - The message to append.
* @param {number} logLevel - The log level associated with the message.
- */
- static putNDJson(message, logLevel){
- let separator = (this.#NDJson.length !== 0) ? '\n' : '';
- this.#NDJson += separator + JSON.stringify({ 'time': new Date().toISOString(), 'level': logLevel, 'msg': message });
+ */
+ static putNDJson(message: string, logLevel: number): void{
+ let separator = (this.NDJsonData.length !== 0) ? '\n' : '';
+ this.NDJsonData += separator + JSON.stringify({ 'time': new Date().toISOString(), 'level': logLevel, 'msg': message });
}
/**
* Gets the NDJson log.
* @returns {string} - The NDJson log.
- */
- static getNDJson(){
- return this.#NDJson;
+ */
+ static getNDJson(): string{
+ return this.NDJsonData ?? '';
}
}
\ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
new file mode 100644
index 0000000..95c20ce
--- /dev/null
+++ b/tsconfig.json
@@ -0,0 +1,22 @@
+{
+ "compilerOptions": {
+ "lib": ["ESNext", "DOM"],
+ "target": "ESNext",
+ "module": "ESNext",
+ "moduleDetection": "force",
+ "jsx": "react-jsx",
+ "allowJs": true,
+
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "verbatimModuleSyntax": true,
+ "noEmit": true,
+
+ /* Linting */
+ "skipLibCheck": true,
+ "strict": true,
+ "noFallthroughCasesInSwitch": true,
+ "forceConsistentCasingInFileNames": true
+ }
+}