zario 0.2.11 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/cjs/core/CustomLogLevel.js +2 -0
- package/dist/cjs/core/Formatter.js +75 -0
- package/dist/cjs/core/LogLevel.js +2 -0
- package/dist/cjs/core/Logger.js +234 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/transports/ConsoleTransport.js +39 -0
- package/dist/cjs/transports/FileTransport.js +260 -0
- package/dist/cjs/transports/HttpTransport.js +150 -0
- package/dist/cjs/transports/Transport.js +2 -0
- package/dist/cjs/transports/index.js +20 -0
- package/dist/cjs/utils/ColorUtil.js +42 -0
- package/dist/cjs/utils/TimeUtil.js +26 -0
- package/dist/cjs/utils/Timerutil.js +22 -0
- package/dist/{core → esm/core}/CustomLogLevel.d.ts +1 -1
- package/dist/esm/core/CustomLogLevel.js +1 -0
- package/dist/{core → esm/core}/Formatter.d.ts +1 -1
- package/dist/esm/core/Formatter.js +71 -0
- package/dist/esm/core/LogLevel.js +1 -0
- package/dist/{core → esm/core}/Logger.d.ts +4 -5
- package/dist/esm/core/Logger.js +230 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +13 -0
- package/dist/{transports → esm/transports}/ConsoleTransport.d.ts +3 -3
- package/dist/esm/transports/ConsoleTransport.js +35 -0
- package/dist/{transports → esm/transports}/FileTransport.d.ts +7 -5
- package/dist/esm/transports/FileTransport.js +223 -0
- package/dist/{transports → esm/transports}/HttpTransport.d.ts +3 -3
- package/dist/esm/transports/HttpTransport.js +113 -0
- package/dist/{transports → esm/transports}/Transport.d.ts +2 -2
- package/dist/esm/transports/Transport.js +1 -0
- package/dist/esm/transports/index.d.ts +4 -0
- package/dist/esm/transports/index.js +4 -0
- package/dist/esm/utils/ColorUtil.js +38 -0
- package/dist/esm/utils/TimeUtil.js +22 -0
- package/dist/esm/utils/Timerutil.js +18 -0
- package/package.json +19 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -3
- package/dist/index.mjs +0 -3
- package/dist/transports/index.d.ts +0 -28
- /package/dist/{core → esm/core}/LogLevel.d.ts +0 -0
- /package/dist/{utils → esm/utils}/ColorUtil.d.ts +0 -0
- /package/dist/{utils → esm/utils}/TimeUtil.d.ts +0 -0
- /package/dist/{utils → esm/utils}/Timerutil.d.ts +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class ColorUtil {
|
|
2
|
+
static colorize(text, color) {
|
|
3
|
+
const supportsColor = process.env.FORCE_COLOR !== "0" &&
|
|
4
|
+
(process.stdout.isTTY || process.env.FORCE_COLOR === "1");
|
|
5
|
+
if (!supportsColor) {
|
|
6
|
+
return text;
|
|
7
|
+
}
|
|
8
|
+
const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
|
|
9
|
+
return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
// ANSI color codes
|
|
13
|
+
ColorUtil.ANSI_COLORS = {
|
|
14
|
+
// Standard colors
|
|
15
|
+
black: "\x1b[30m",
|
|
16
|
+
red: "\x1b[31m",
|
|
17
|
+
green: "\x1b[32m",
|
|
18
|
+
yellow: "\x1b[33m",
|
|
19
|
+
blue: "\x1b[34m",
|
|
20
|
+
magenta: "\x1b[35m",
|
|
21
|
+
cyan: "\x1b[36m",
|
|
22
|
+
white: "\x1b[37m",
|
|
23
|
+
// Bright colors
|
|
24
|
+
brightRed: "\x1b[91m",
|
|
25
|
+
brightGreen: "\x1b[92m",
|
|
26
|
+
brightYellow: "\x1b[93m",
|
|
27
|
+
brightBlue: "\x1b[94m",
|
|
28
|
+
brightMagenta: "\x1b[95m",
|
|
29
|
+
brightCyan: "\x1b[96m",
|
|
30
|
+
brightWhite: "\x1b[97m",
|
|
31
|
+
// Default log level colors
|
|
32
|
+
info: "\x1b[32m",
|
|
33
|
+
warn: "\x1b[33m",
|
|
34
|
+
error: "\x1b[31m",
|
|
35
|
+
debug: "\x1b[36m",
|
|
36
|
+
boring: "\x1b[37m",
|
|
37
|
+
reset: "\x1b[0m",
|
|
38
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class TimeUtil {
|
|
2
|
+
// util class for date formating
|
|
3
|
+
static format(date, format) {
|
|
4
|
+
if (format === "ISO")
|
|
5
|
+
return date.toISOString();
|
|
6
|
+
if (format === "UTC")
|
|
7
|
+
return date.toUTCString();
|
|
8
|
+
if (format === "LOCAL")
|
|
9
|
+
return date.toLocaleString();
|
|
10
|
+
const pad = (n, width = 2) => n.toString().padStart(width, "0");
|
|
11
|
+
const tokens = {
|
|
12
|
+
YYYY: pad(date.getFullYear(), 4),
|
|
13
|
+
MM: pad(date.getMonth() + 1),
|
|
14
|
+
DD: pad(date.getDate()),
|
|
15
|
+
HH: pad(date.getHours()),
|
|
16
|
+
mm: pad(date.getMinutes()),
|
|
17
|
+
ss: pad(date.getSeconds()),
|
|
18
|
+
SSS: pad(date.getMilliseconds(), 3),
|
|
19
|
+
};
|
|
20
|
+
return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class Timer {
|
|
2
|
+
constructor(name, logFn) {
|
|
3
|
+
this.hasEnded = false;
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.logFn = logFn;
|
|
6
|
+
this.startTime = Date.now();
|
|
7
|
+
}
|
|
8
|
+
end() {
|
|
9
|
+
// If already ended, do nothing (idempotent)
|
|
10
|
+
if (this.hasEnded) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const endTime = Date.now();
|
|
14
|
+
const duration = endTime - this.startTime;
|
|
15
|
+
this.logFn(`${this.name} took ${duration}ms`);
|
|
16
|
+
this.hasEnded = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zario",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A minimal, fast logging library for Node.js.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.
|
|
12
|
-
"require": "./dist/index.js"
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./core/*": {
|
|
15
|
+
"types": "./dist/esm/core/*.d.ts",
|
|
16
|
+
"import": "./dist/esm/core/*.js",
|
|
17
|
+
"require": "./dist/cjs/core/*.js"
|
|
18
|
+
},
|
|
19
|
+
"./transports/*": {
|
|
20
|
+
"types": "./dist/esm/transports/*.d.ts",
|
|
21
|
+
"import": "./dist/esm/transports/*.js",
|
|
22
|
+
"require": "./dist/cjs/transports/*.js"
|
|
13
23
|
}
|
|
14
24
|
},
|
|
15
25
|
"scripts": {
|
|
16
|
-
"build": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\" &&
|
|
26
|
+
"build": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\" && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', '{\\\"type\\\":\\\"commonjs\\\"}')\"",
|
|
17
27
|
"dev": "tsc --watch",
|
|
18
28
|
"test": "jest",
|
|
19
29
|
"lint": "eslint . --ext .ts,.js",
|
|
@@ -33,6 +43,7 @@
|
|
|
33
43
|
],
|
|
34
44
|
"author": "Dev-dami",
|
|
35
45
|
"license": "MIT",
|
|
46
|
+
"sideEffects": false,
|
|
36
47
|
"type": "module",
|
|
37
48
|
"bugs": {
|
|
38
49
|
"url": "https://github.com/Dev-Dami/zario/issues"
|
package/dist/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Logger } from './core/Logger';
|
|
2
|
-
import { LogLevel } from './core/LogLevel';
|
|
3
|
-
import { ConsoleTransport, FileTransport, HttpTransport, Transport, consoleT, fileT, httpT } from './transports';
|
|
4
|
-
import { TransportConfig, LoggerConfig } from './types/index';
|
|
5
|
-
import { CustomLogLevelConfig } from './core/CustomLogLevel';
|
|
6
|
-
export { Logger, ConsoleTransport, FileTransport, HttpTransport, consoleT, fileT, httpT };
|
|
7
|
-
export type { LogLevel, Transport, TransportConfig, LoggerConfig, CustomLogLevelConfig };
|
|
8
|
-
export default Logger;
|
package/dist/index.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use strict";var N=Object.create;var F=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(a,t)=>()=>(a&&(t=a(a=0)),t);var z=(a,t)=>{for(var e in t)F(a,e,{get:t[e],enumerable:!0})},D=(a,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Y(t))!q.call(a,o)&&o!==e&&F(a,o,{get:()=>t[o],enumerable:!(s=k(t,o))||s.enumerable});return a};var y=(a,t,e)=>(e=a!=null?N(B(a)):{},D(t||!a||!a.__esModule?F(e,"default",{value:a,enumerable:!0}):e,a)),R=a=>D(F({},"__esModule",{value:!0}),a);var M={};z(M,{Timer:()=>S});var S,H=J(()=>{"use strict";S=class{constructor(t,e){this.hasEnded=!1;this.name=t,this.logFn=e,this.startTime=Date.now()}end(){if(this.hasEnded)return;let e=Date.now()-this.startTime;this.logFn(`${this.name} took ${e}ms`),this.hasEnded=!0}}});var K={};z(K,{ConsoleTransport:()=>f,FileTransport:()=>d,HttpTransport:()=>T,Logger:()=>x,consoleT:()=>E,default:()=>_,fileT:()=>A,httpT:()=>$});module.exports=R(K);var w=class{static format(t,e){if(e==="ISO")return t.toISOString();if(e==="UTC")return t.toUTCString();if(e==="LOCAL")return t.toLocaleString();let s=t.getFullYear(),o=t.getMonth()+1,r=t.getDate(),n=t.getHours(),p=t.getMinutes(),c=t.getSeconds(),u=t.getMilliseconds(),h=[],i=0,g=0;for(;i<e.length;)e[i]==="Y"&&i+3<e.length&&e.slice(i,i+4)==="YYYY"?(h.push(e.substring(g,i)),h.push(s.toString().padStart(4,"0")),i+=4,g=i):e[i]==="M"&&i+1<e.length&&e.slice(i,i+2)==="MM"?(h.push(e.substring(g,i)),h.push(o.toString().padStart(2,"0")),i+=2,g=i):e[i]==="D"&&i+1<e.length&&e.slice(i,i+2)==="DD"?(h.push(e.substring(g,i)),h.push(r.toString().padStart(2,"0")),i+=2,g=i):e[i]==="H"&&i+1<e.length&&e.slice(i,i+2)==="HH"?(h.push(e.substring(g,i)),h.push(n.toString().padStart(2,"0")),i+=2,g=i):e[i]==="m"&&i+1<e.length&&e.slice(i,i+2)==="mm"?(h.push(e.substring(g,i)),h.push(p.toString().padStart(2,"0")),i+=2,g=i):e[i]==="s"&&i+1<e.length&&e.slice(i,i+2)==="ss"?(h.push(e.substring(g,i)),h.push(c.toString().padStart(2,"0")),i+=2,g=i):e[i]==="S"&&i+2<e.length&&e.slice(i,i+3)==="SSS"?(h.push(e.substring(g,i)),h.push(u.toString().padStart(3,"0")),i+=3,g=i):i++;return h.push(e.substring(g)),h.join("")}};var O=class a{static{this.ANSI_COLORS={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",info:"\x1B[32m",warn:"\x1B[33m",error:"\x1B[31m",debug:"\x1B[36m",boring:"\x1B[37m",reset:"\x1B[0m"}}static colorize(t,e){return process.env.FORCE_COLOR!=="0"&&(process.stdout.isTTY||process.env.FORCE_COLOR==="1")?`${a.ANSI_COLORS[e]||a.ANSI_COLORS.reset}${t}${a.ANSI_COLORS.reset}`:t}};var L=class{constructor(t={}){let{colorize:e=!0,json:s=!1,timestampFormat:o="YYYY-MM-DD HH:mm:ss",timestamp:r=!1,customColors:n={}}=t;this.colorize=e,this.json=s,this.timestampFormat=o,this.timestamp=r,this.customColors=n}format(t){return this.json?this.formatAsJson(t):this.formatAsText(t)}formatAsJson(t){let e={...t.metadata,level:t.level,message:t.message};return this.timestamp&&(e.timestamp=t.timestamp.toISOString()),t.prefix&&(e.prefix=t.prefix),JSON.stringify(e)}formatAsText(t){let e=[];if(this.timestamp){let o=w.format(t.timestamp,this.timestampFormat);e.push(`[${o}] `)}t.prefix&&e.push(`${t.prefix} `);let s=t.level.toUpperCase();if(this.colorize){let o=this.customColors[t.level]||t.level;s=O.colorize(s,o)}return e.push(`[${s}] `),e.push(t.message),t.metadata&&e.push(` ${JSON.stringify(t.metadata)}`),e.join("")}setJson(t){this.json=t}isColorized(){return this.colorize}isJson(){return this.json}getTimestampFormat(){return this.timestampFormat}hasTimestamp(){return this.timestamp}getCustomColors(){return{...this.customColors}}};var f=class{constructor(t={}){let{colorize:e=!0}=t;this.colorize=e}write(t,e){let s=e.colorize;this.colorize!==s&&(e.colorize=this.colorize);let o=e.format(t);switch(this.colorize!==s&&(e.colorize=s),t.level){case"error":console.error(o);break;case"warn":console.warn(o);break;default:console.log(o);break}}async writeAsync(t,e){return setImmediate(()=>{this.write(t,e)}),Promise.resolve()}};var l=y(require("fs"),1),m=y(require("path"),1),b=y(require("zlib"),1),C=require("util"),Q=(0,C.promisify)(b.gzip),V=(0,C.promisify)(b.deflate),d=class{constructor(t){this.batchQueue=[];this.batchTimer=null;let{path:e,maxSize:s=10*1024*1024,maxFiles:o=5,compression:r="none",batchInterval:n=0,compressOldFiles:p=!0}=t;this.filePath=e,this.maxSize=s,this.maxFiles=o,this.compression=r,this.batchInterval=n,this.compressOldFiles=p;let c=m.dirname(this.filePath);l.existsSync(c)||l.mkdirSync(c,{recursive:!0}),l.existsSync(this.filePath)||l.writeFileSync(this.filePath,"","utf8"),n>0&&this.startBatching()}write(t,e){let o=e.format(t)+`
|
|
2
|
-
`;this.batchInterval>0?this.batchQueue.push({data:o,timestamp:new Date}):(l.appendFileSync(this.filePath,o),this.rotateIfNeeded())}async writeAsync(t,e){let o=e.format(t)+`
|
|
3
|
-
`;this.batchInterval>0?this.batchQueue.push({data:o,timestamp:new Date}):(await new Promise((r,n)=>{l.appendFile(this.filePath,o,p=>{if(p){n(p);return}r()})}),await this.rotateIfNeededAsync())}rotateIfNeeded(){if(l.existsSync(this.filePath))try{l.statSync(this.filePath).size>=this.maxSize&&this.rotateFiles()}catch(t){console.error("Error checking file size for rotation:",t)}}async rotateIfNeededAsync(){if(l.existsSync(this.filePath))try{l.statSync(this.filePath).size>=this.maxSize&&await this.rotateFilesAsync()}catch(t){console.error("Error during rotation check:",t)}}rotateFiles(){try{let t="";l.existsSync(this.filePath)&&(t=l.readFileSync(this.filePath,"utf8"));let e=this.getRotatedFilePath();if(this.compression!=="none"&&this.compressOldFiles){e=`${e}.${this.compression==="gzip"?"gz":"zz"}`;let s=this.compression==="gzip"?b.gzipSync(t):b.deflateSync(t);l.writeFileSync(e,s)}else l.writeFileSync(e,t,"utf8");l.writeFileSync(this.filePath,"","utf8"),this.cleanupOldFiles()}catch(t){console.error("Error during file rotation:",t)}}async rotateFilesAsync(){try{let t="";l.existsSync(this.filePath)&&(t=await l.promises.readFile(this.filePath,"utf8"));let e=this.getRotatedFilePath();if(this.compression!=="none"&&this.compressOldFiles){e=`${e}.${this.compression==="gzip"?"gz":"zz"}`;let s=this.compression==="gzip"?await Q(t):await V(t);await l.promises.writeFile(e,s)}else await l.promises.writeFile(e,t,"utf8");await l.promises.writeFile(this.filePath,"","utf8"),await this.cleanupOldFilesAsync()}catch(t){console.error("Error during async file rotation:",t)}}getRotatedFilePath(){let t=m.dirname(this.filePath),e=m.basename(this.filePath),s=Date.now();return m.join(t,`${e}.${s}`)}cleanupOldFiles(){try{let t=m.dirname(this.filePath),e=m.basename(this.filePath);try{l.accessSync(t,l.constants.F_OK)}catch{return}let o=l.readdirSync(t).filter(r=>!r||r===e?!1:new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\.\\d+(\\.gz|\\.zz)?$`).test(r)).sort((r,n)=>{let p=parseInt(r.slice(e.length+1).split(".")[0]||"0");return parseInt(n.slice(e.length+1).split(".")[0]||"0")-p});for(let r=this.maxFiles;r<o.length;r++){let n=o[r];if(n){if(n.includes("../")||n.includes("..\\")||n.startsWith(".."))continue;let p=m.join(t,n),c=m.resolve(p),u=m.resolve(t);if(!c.startsWith(u+m.sep)&&c!==u)continue;try{l.unlinkSync(p)}catch(h){console.error(`Failed to delete old log file ${p}:`,h)}}}}catch(t){console.error("Error during cleanup of old files:",t)}}async cleanupOldFilesAsync(){try{let t=m.dirname(this.filePath),e=m.basename(this.filePath);try{await l.promises.access(t,l.constants.F_OK)}catch{return}let o=(await l.promises.readdir(t)).filter(n=>!n||n===e?!1:new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\.\\d+(\\.gz|\\.zz)?$`).test(n)).sort((n,p)=>{let c=parseInt(n.slice(e.length+1).split(".")[0]||"0");return parseInt(p.slice(e.length+1).split(".")[0]||"0")-c}),r=[];for(let n=this.maxFiles;n<o.length;n++){let p=o[n];if(p){if(p.includes("../")||p.includes("..\\")||p.startsWith(".."))continue;let c=m.join(t,p),u=m.resolve(c),h=m.resolve(t);if(!u.startsWith(h+m.sep)&&u!==h)continue;r.push(l.promises.access(c,l.constants.F_OK).then(()=>l.promises.unlink(c)).catch(i=>{i.code!=="ENOENT"&&console.error(`Failed to delete old log file ${c}:`,i)}))}}await Promise.all(r)}catch(t){console.error("Error during async cleanup of old files:",t)}}startBatching(){this.batchInterval>0&&(this.batchTimer=setInterval(()=>{this.processBatch().catch(t=>{console.error("Error in batch processing timer:",t)})},this.batchInterval))}async processBatch(){if(this.batchQueue.length===0)return;let t=this.batchQueue;this.batchQueue=[];let e=t.map(s=>s.data).join("");try{await new Promise((s,o)=>{l.appendFile(this.filePath,e,r=>{if(r){o(r);return}s()})}),await this.rotateIfNeededAsync()}catch(s){console.error("Error processing log batch:",s),this.batchQueue=[...t,...this.batchQueue]}}async destroy(){if(this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=null),this.batchQueue.length>0)try{await this.processBatch()}catch(t){console.error("Error processing final batch:",t)}}};var W=y(require("http"),1),U=y(require("https"),1),I=y(require("url"),1),T=class{constructor(t){let{url:e,method:s="POST",headers:o={},timeout:r=5e3,retries:n=3}=t;if(!e)throw new Error("HttpTransport requires a URL option");this.url=e,this.method=s.toUpperCase(),this.headers={...o},this.timeout=r,this.retries=n,!this.headers["Content-Type"]&&!this.headers["content-type"]&&(this.headers["Content-Type"]="application/json")}write(t,e){let s=this.parseFormattedData(t),o=JSON.stringify(s);setImmediate(()=>{this.sendHttpRequestWithRetry(o,0).catch(r=>{console.error("HttpTransport error (sync mode):",r.message)})})}async writeAsync(t,e){let s=this.parseFormattedData(t),o=JSON.stringify(s);await this.sendHttpRequestWithRetry(o,this.retries)}parseFormattedData(t){return{level:t.level,message:t.message,timestamp:t.timestamp.toISOString(),...t.prefix&&{prefix:t.prefix},...t.metadata&&{metadata:t.metadata}}}async sendHttpRequestWithRetry(t,e){let s=null;for(let o=0;o<=e;o++)try{await this.sendHttpRequest(t);return}catch(r){if(s=r,o===e)break;await this.delay(Math.pow(2,o)*1e3)}if(s)throw s}sendHttpRequest(t){return new Promise((e,s)=>{let o=new I.URL(this.url),n=o.protocol==="https:"?U:W,p={hostname:o.hostname,port:o.port,path:o.pathname+o.search,method:this.method,headers:{...this.headers,"Content-Length":Buffer.byteLength(t,"utf8")},timeout:this.timeout},c=n.request(p,u=>{let h="";u.on("data",i=>{h+=i}),u.on("end",()=>{u.statusCode&&u.statusCode>=200&&u.statusCode<300?e():s(new Error(`HTTP request failed with status ${u.statusCode}: ${h}`))})});c.on("error",u=>{s(u)}),c.on("timeout",()=>{c.destroy(),s(new Error("Request timeout"))}),c.write(t),c.end()})}delay(t){return new Promise(e=>setTimeout(e,t))}};function E(a){return new f(a)}function A(a){return new d(a)}function $(a){return new T(a)}var x=class a{constructor(t={}){this.transports=[];let{level:e,colorize:s,json:o,transports:r=[],timestampFormat:n="YYYY-MM-DD HH:mm:ss",prefix:p,timestamp:c,context:u={},parent:h,asyncMode:i,customLevels:g={},customColors:P={}}=t;if(this.parent=h,this.context={...u},this.customLevels=g,this.asyncMode=!1,this.parent){this.level=e??this.parent.level,this.prefix=p??this.parent.prefix,this.timestamp=c??this.parent.timestamp,this.asyncMode=i??this.parent.asyncMode,this.transports=r&&r.length>0?this.initTransports(r,this.getDefaultColorizeValue(s)):this.parent.transports;let v={...this.parent.formatter.getCustomColors(),...P};this.formatter=new L({colorize:this.getDefaultColorizeValue(s)??this.parent.formatter.isColorized(),json:o??this.parent.formatter.isJson(),timestampFormat:n??this.parent.formatter.getTimestampFormat(),timestamp:c??this.parent.formatter.hasTimestamp(),customColors:v}),this.context={...this.parent.context,...this.context},this.customLevels={...this.parent.customLevels,...g}}else{let v=this.isProductionEnvironment();this.level=e??this.getDefaultLevel(v),this.prefix=p??"",this.timestamp=c??this.getDefaultTimestamp(v);let j=r&&r.length>0?r:this.getDefaultTransports(v);this.asyncMode=i??this.getDefaultAsyncMode(v),this.transports=this.initTransports(j,this.getDefaultColorizeValue(s)),this.formatter=new L({colorize:this.getDefaultColorizeValue(s),json:o??this.getDefaultJson(v),timestampFormat:n,timestamp:this.getDefaultTimestamp(v),customColors:P})}a._global||(a._global=this)}static{this.LEVEL_PRIORITIES={silent:0,boring:1,debug:2,info:3,warn:4,error:5}}isProductionEnvironment(){let t=process.env.NODE_ENV?.toLowerCase();return t==="production"||t==="prod"}getDefaultLevel(t){return t?"warn":"debug"}getDefaultColorizeValue(t){return t!==void 0?t:!this.isProductionEnvironment()}getDefaultJson(t){return t}getDefaultTimestamp(t){return!0}getDefaultTransports(t){return t?[new f,new d({path:"./logs/app.log"})]:[new f]}getDefaultAsyncMode(t){return t}initTransports(t,e){let s=[];for(let o of t)if(this.isLegacyTransportOptions(o)){let r=o;if(r.type==="console"){let n=new f({colorize:r.options?.colorize??e});s.push(n)}else if(r.type==="file"){if(r.options?.path){let n={path:r.options.path};r.options.maxSize!==void 0&&(n.maxSize=r.options.maxSize),r.options.maxFiles!==void 0&&(n.maxFiles=r.options.maxFiles),r.options.compression!==void 0&&(n.compression=r.options.compression),r.options.batchInterval!==void 0&&(n.batchInterval=r.options.batchInterval),r.options.compressOldFiles!==void 0&&(n.compressOldFiles=r.options.compressOldFiles);let p=new d(n);s.push(p)}}else r.type==="custom"&&r.instance&&s.push(r.instance)}else this.isTransport(o)&&s.push(o);return s}isLegacyTransportOptions(t){return typeof t=="object"&&t!==null&&"type"in t}isTransport(t){return t&&typeof t.write=="function"&&(typeof t.writeAsync=="function"||t.writeAsync===void 0)}shouldLog(t){let e=this.getLevelPriority(this.level);return this.getLevelPriority(t)>=e}getLevelPriority(t){if(a.LEVEL_PRIORITIES.hasOwnProperty(t))return a.LEVEL_PRIORITIES[t];if(this.customLevels&&t in this.customLevels){let e=this.customLevels[t];return e!==void 0?e:999}return 999}log(t,e,s){if(this.shouldLog(t)&&t!=="silent")if(this.asyncMode)this.logAsyncDirect(t,e,s);else{let o=new Date,r;this.context&&Object.keys(this.context).length>0?s?r={...this.context,...s}:r=this.context:s&&(r=s);let n={level:t,message:e,timestamp:o,metadata:r&&Object.keys(r).length>0?r:void 0,prefix:this.prefix};for(let p of this.transports)p.write(n,this.formatter)}}logAsyncDirect(t,e,s){if(!this.shouldLog(t)||t==="silent")return;let o=new Date,r;this.context&&Object.keys(this.context).length>0?s?r={...this.context,...s}:r=this.context:s&&(r=s);let n={level:t,message:e,timestamp:o,metadata:r&&Object.keys(r).length>0?r:void 0,prefix:this.prefix};for(let p of this.transports)p.writeAsync?p.writeAsync(n,this.formatter).catch(c=>{console.error("Error during async logging:",c)}):setImmediate(()=>{p.write(n,this.formatter)})}debug(t,e){this.log("debug",t,e)}info(t,e){this.log("info",t,e)}warn(t,e){this.log("warn",t,e)}error(t,e){this.log("error",t,e)}silent(t,e){this.log("silent",t,e)}boring(t,e){this.log("boring",t,e)}logWithLevel(t,e,s){this.log(t,e,s)}setLevel(t){this.level=t}setFormat(t){this.formatter.setJson(t==="json")}setAsyncMode(t){this.asyncMode=t}addTransport(t){this.transports.push(t)}getTimestampSetting(){return this.timestamp}static get global(){return a._global||(a._global=new a),a._global}createChild(t={}){return new a({...t,parent:this})}startTimer(t){let{Timer:e}=(H(),R(M));return new e(t,s=>this.info(s))}};var _=x;0&&(module.exports={ConsoleTransport,FileTransport,HttpTransport,Logger,consoleT,fileT,httpT});
|
package/dist/index.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var w=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var $=(l,t)=>()=>(l&&(t=l(l=0)),t);var M=(l,t)=>{for(var e in t)w(l,e,{get:t[e],enumerable:!0})},H=(l,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of E(t))!A.call(l,o)&&o!==e&&w(l,o,{get:()=>t[o],enumerable:!(s=I(t,o))||s.enumerable});return l};var j=l=>H(w({},"__esModule",{value:!0}),l);var z={};M(z,{Timer:()=>O});var O,D=$(()=>{"use strict";O=class{constructor(t,e){this.hasEnded=!1;this.name=t,this.logFn=e,this.startTime=Date.now()}end(){if(this.hasEnded)return;let e=Date.now()-this.startTime;this.logFn(`${this.name} took ${e}ms`),this.hasEnded=!0}}});var L=class{static format(t,e){if(e==="ISO")return t.toISOString();if(e==="UTC")return t.toUTCString();if(e==="LOCAL")return t.toLocaleString();let s=t.getFullYear(),o=t.getMonth()+1,r=t.getDate(),n=t.getHours(),p=t.getMinutes(),c=t.getSeconds(),u=t.getMilliseconds(),h=[],i=0,g=0;for(;i<e.length;)e[i]==="Y"&&i+3<e.length&&e.slice(i,i+4)==="YYYY"?(h.push(e.substring(g,i)),h.push(s.toString().padStart(4,"0")),i+=4,g=i):e[i]==="M"&&i+1<e.length&&e.slice(i,i+2)==="MM"?(h.push(e.substring(g,i)),h.push(o.toString().padStart(2,"0")),i+=2,g=i):e[i]==="D"&&i+1<e.length&&e.slice(i,i+2)==="DD"?(h.push(e.substring(g,i)),h.push(r.toString().padStart(2,"0")),i+=2,g=i):e[i]==="H"&&i+1<e.length&&e.slice(i,i+2)==="HH"?(h.push(e.substring(g,i)),h.push(n.toString().padStart(2,"0")),i+=2,g=i):e[i]==="m"&&i+1<e.length&&e.slice(i,i+2)==="mm"?(h.push(e.substring(g,i)),h.push(p.toString().padStart(2,"0")),i+=2,g=i):e[i]==="s"&&i+1<e.length&&e.slice(i,i+2)==="ss"?(h.push(e.substring(g,i)),h.push(c.toString().padStart(2,"0")),i+=2,g=i):e[i]==="S"&&i+2<e.length&&e.slice(i,i+3)==="SSS"?(h.push(e.substring(g,i)),h.push(u.toString().padStart(3,"0")),i+=3,g=i):i++;return h.push(e.substring(g)),h.join("")}};var x=class l{static{this.ANSI_COLORS={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m",info:"\x1B[32m",warn:"\x1B[33m",error:"\x1B[31m",debug:"\x1B[36m",boring:"\x1B[37m",reset:"\x1B[0m"}}static colorize(t,e){return process.env.FORCE_COLOR!=="0"&&(process.stdout.isTTY||process.env.FORCE_COLOR==="1")?`${l.ANSI_COLORS[e]||l.ANSI_COLORS.reset}${t}${l.ANSI_COLORS.reset}`:t}};var y=class{constructor(t={}){let{colorize:e=!0,json:s=!1,timestampFormat:o="YYYY-MM-DD HH:mm:ss",timestamp:r=!1,customColors:n={}}=t;this.colorize=e,this.json=s,this.timestampFormat=o,this.timestamp=r,this.customColors=n}format(t){return this.json?this.formatAsJson(t):this.formatAsText(t)}formatAsJson(t){let e={...t.metadata,level:t.level,message:t.message};return this.timestamp&&(e.timestamp=t.timestamp.toISOString()),t.prefix&&(e.prefix=t.prefix),JSON.stringify(e)}formatAsText(t){let e=[];if(this.timestamp){let o=L.format(t.timestamp,this.timestampFormat);e.push(`[${o}] `)}t.prefix&&e.push(`${t.prefix} `);let s=t.level.toUpperCase();if(this.colorize){let o=this.customColors[t.level]||t.level;s=x.colorize(s,o)}return e.push(`[${s}] `),e.push(t.message),t.metadata&&e.push(` ${JSON.stringify(t.metadata)}`),e.join("")}setJson(t){this.json=t}isColorized(){return this.colorize}isJson(){return this.json}getTimestampFormat(){return this.timestampFormat}hasTimestamp(){return this.timestamp}getCustomColors(){return{...this.customColors}}};var f=class{constructor(t={}){let{colorize:e=!0}=t;this.colorize=e}write(t,e){let s=e.colorize;this.colorize!==s&&(e.colorize=this.colorize);let o=e.format(t);switch(this.colorize!==s&&(e.colorize=s),t.level){case"error":console.error(o);break;case"warn":console.warn(o);break;default:console.log(o);break}}async writeAsync(t,e){return setImmediate(()=>{this.write(t,e)}),Promise.resolve()}};import*as a from"fs";import*as m from"path";import*as b from"zlib";import{promisify as S}from"util";var N=S(b.gzip),k=S(b.deflate),v=class{constructor(t){this.batchQueue=[];this.batchTimer=null;let{path:e,maxSize:s=10*1024*1024,maxFiles:o=5,compression:r="none",batchInterval:n=0,compressOldFiles:p=!0}=t;this.filePath=e,this.maxSize=s,this.maxFiles=o,this.compression=r,this.batchInterval=n,this.compressOldFiles=p;let c=m.dirname(this.filePath);a.existsSync(c)||a.mkdirSync(c,{recursive:!0}),a.existsSync(this.filePath)||a.writeFileSync(this.filePath,"","utf8"),n>0&&this.startBatching()}write(t,e){let o=e.format(t)+`
|
|
2
|
-
`;this.batchInterval>0?this.batchQueue.push({data:o,timestamp:new Date}):(a.appendFileSync(this.filePath,o),this.rotateIfNeeded())}async writeAsync(t,e){let o=e.format(t)+`
|
|
3
|
-
`;this.batchInterval>0?this.batchQueue.push({data:o,timestamp:new Date}):(await new Promise((r,n)=>{a.appendFile(this.filePath,o,p=>{if(p){n(p);return}r()})}),await this.rotateIfNeededAsync())}rotateIfNeeded(){if(a.existsSync(this.filePath))try{a.statSync(this.filePath).size>=this.maxSize&&this.rotateFiles()}catch(t){console.error("Error checking file size for rotation:",t)}}async rotateIfNeededAsync(){if(a.existsSync(this.filePath))try{a.statSync(this.filePath).size>=this.maxSize&&await this.rotateFilesAsync()}catch(t){console.error("Error during rotation check:",t)}}rotateFiles(){try{let t="";a.existsSync(this.filePath)&&(t=a.readFileSync(this.filePath,"utf8"));let e=this.getRotatedFilePath();if(this.compression!=="none"&&this.compressOldFiles){e=`${e}.${this.compression==="gzip"?"gz":"zz"}`;let s=this.compression==="gzip"?b.gzipSync(t):b.deflateSync(t);a.writeFileSync(e,s)}else a.writeFileSync(e,t,"utf8");a.writeFileSync(this.filePath,"","utf8"),this.cleanupOldFiles()}catch(t){console.error("Error during file rotation:",t)}}async rotateFilesAsync(){try{let t="";a.existsSync(this.filePath)&&(t=await a.promises.readFile(this.filePath,"utf8"));let e=this.getRotatedFilePath();if(this.compression!=="none"&&this.compressOldFiles){e=`${e}.${this.compression==="gzip"?"gz":"zz"}`;let s=this.compression==="gzip"?await N(t):await k(t);await a.promises.writeFile(e,s)}else await a.promises.writeFile(e,t,"utf8");await a.promises.writeFile(this.filePath,"","utf8"),await this.cleanupOldFilesAsync()}catch(t){console.error("Error during async file rotation:",t)}}getRotatedFilePath(){let t=m.dirname(this.filePath),e=m.basename(this.filePath),s=Date.now();return m.join(t,`${e}.${s}`)}cleanupOldFiles(){try{let t=m.dirname(this.filePath),e=m.basename(this.filePath);try{a.accessSync(t,a.constants.F_OK)}catch{return}let o=a.readdirSync(t).filter(r=>!r||r===e?!1:new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\.\\d+(\\.gz|\\.zz)?$`).test(r)).sort((r,n)=>{let p=parseInt(r.slice(e.length+1).split(".")[0]||"0");return parseInt(n.slice(e.length+1).split(".")[0]||"0")-p});for(let r=this.maxFiles;r<o.length;r++){let n=o[r];if(n){if(n.includes("../")||n.includes("..\\")||n.startsWith(".."))continue;let p=m.join(t,n),c=m.resolve(p),u=m.resolve(t);if(!c.startsWith(u+m.sep)&&c!==u)continue;try{a.unlinkSync(p)}catch(h){console.error(`Failed to delete old log file ${p}:`,h)}}}}catch(t){console.error("Error during cleanup of old files:",t)}}async cleanupOldFilesAsync(){try{let t=m.dirname(this.filePath),e=m.basename(this.filePath);try{await a.promises.access(t,a.constants.F_OK)}catch{return}let o=(await a.promises.readdir(t)).filter(n=>!n||n===e?!1:new RegExp(`^${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\.\\d+(\\.gz|\\.zz)?$`).test(n)).sort((n,p)=>{let c=parseInt(n.slice(e.length+1).split(".")[0]||"0");return parseInt(p.slice(e.length+1).split(".")[0]||"0")-c}),r=[];for(let n=this.maxFiles;n<o.length;n++){let p=o[n];if(p){if(p.includes("../")||p.includes("..\\")||p.startsWith(".."))continue;let c=m.join(t,p),u=m.resolve(c),h=m.resolve(t);if(!u.startsWith(h+m.sep)&&u!==h)continue;r.push(a.promises.access(c,a.constants.F_OK).then(()=>a.promises.unlink(c)).catch(i=>{i.code!=="ENOENT"&&console.error(`Failed to delete old log file ${c}:`,i)}))}}await Promise.all(r)}catch(t){console.error("Error during async cleanup of old files:",t)}}startBatching(){this.batchInterval>0&&(this.batchTimer=setInterval(()=>{this.processBatch().catch(t=>{console.error("Error in batch processing timer:",t)})},this.batchInterval))}async processBatch(){if(this.batchQueue.length===0)return;let t=this.batchQueue;this.batchQueue=[];let e=t.map(s=>s.data).join("");try{await new Promise((s,o)=>{a.appendFile(this.filePath,e,r=>{if(r){o(r);return}s()})}),await this.rotateIfNeededAsync()}catch(s){console.error("Error processing log batch:",s),this.batchQueue=[...t,...this.batchQueue]}}async destroy(){if(this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=null),this.batchQueue.length>0)try{await this.processBatch()}catch(t){console.error("Error processing final batch:",t)}}};import*as Y from"http";import*as B from"https";import*as P from"url";var T=class{constructor(t){let{url:e,method:s="POST",headers:o={},timeout:r=5e3,retries:n=3}=t;if(!e)throw new Error("HttpTransport requires a URL option");this.url=e,this.method=s.toUpperCase(),this.headers={...o},this.timeout=r,this.retries=n,!this.headers["Content-Type"]&&!this.headers["content-type"]&&(this.headers["Content-Type"]="application/json")}write(t,e){let s=this.parseFormattedData(t),o=JSON.stringify(s);setImmediate(()=>{this.sendHttpRequestWithRetry(o,0).catch(r=>{console.error("HttpTransport error (sync mode):",r.message)})})}async writeAsync(t,e){let s=this.parseFormattedData(t),o=JSON.stringify(s);await this.sendHttpRequestWithRetry(o,this.retries)}parseFormattedData(t){return{level:t.level,message:t.message,timestamp:t.timestamp.toISOString(),...t.prefix&&{prefix:t.prefix},...t.metadata&&{metadata:t.metadata}}}async sendHttpRequestWithRetry(t,e){let s=null;for(let o=0;o<=e;o++)try{await this.sendHttpRequest(t);return}catch(r){if(s=r,o===e)break;await this.delay(Math.pow(2,o)*1e3)}if(s)throw s}sendHttpRequest(t){return new Promise((e,s)=>{let o=new P.URL(this.url),n=o.protocol==="https:"?B:Y,p={hostname:o.hostname,port:o.port,path:o.pathname+o.search,method:this.method,headers:{...this.headers,"Content-Length":Buffer.byteLength(t,"utf8")},timeout:this.timeout},c=n.request(p,u=>{let h="";u.on("data",i=>{h+=i}),u.on("end",()=>{u.statusCode&&u.statusCode>=200&&u.statusCode<300?e():s(new Error(`HTTP request failed with status ${u.statusCode}: ${h}`))})});c.on("error",u=>{s(u)}),c.on("timeout",()=>{c.destroy(),s(new Error("Request timeout"))}),c.write(t),c.end()})}delay(t){return new Promise(e=>setTimeout(e,t))}};function q(l){return new f(l)}function J(l){return new v(l)}function Q(l){return new T(l)}var F=class l{constructor(t={}){this.transports=[];let{level:e,colorize:s,json:o,transports:r=[],timestampFormat:n="YYYY-MM-DD HH:mm:ss",prefix:p,timestamp:c,context:u={},parent:h,asyncMode:i,customLevels:g={},customColors:C={}}=t;if(this.parent=h,this.context={...u},this.customLevels=g,this.asyncMode=!1,this.parent){this.level=e??this.parent.level,this.prefix=p??this.parent.prefix,this.timestamp=c??this.parent.timestamp,this.asyncMode=i??this.parent.asyncMode,this.transports=r&&r.length>0?this.initTransports(r,this.getDefaultColorizeValue(s)):this.parent.transports;let d={...this.parent.formatter.getCustomColors(),...C};this.formatter=new y({colorize:this.getDefaultColorizeValue(s)??this.parent.formatter.isColorized(),json:o??this.parent.formatter.isJson(),timestampFormat:n??this.parent.formatter.getTimestampFormat(),timestamp:c??this.parent.formatter.hasTimestamp(),customColors:d}),this.context={...this.parent.context,...this.context},this.customLevels={...this.parent.customLevels,...g}}else{let d=this.isProductionEnvironment();this.level=e??this.getDefaultLevel(d),this.prefix=p??"",this.timestamp=c??this.getDefaultTimestamp(d);let R=r&&r.length>0?r:this.getDefaultTransports(d);this.asyncMode=i??this.getDefaultAsyncMode(d),this.transports=this.initTransports(R,this.getDefaultColorizeValue(s)),this.formatter=new y({colorize:this.getDefaultColorizeValue(s),json:o??this.getDefaultJson(d),timestampFormat:n,timestamp:this.getDefaultTimestamp(d),customColors:C})}l._global||(l._global=this)}static{this.LEVEL_PRIORITIES={silent:0,boring:1,debug:2,info:3,warn:4,error:5}}isProductionEnvironment(){let t=process.env.NODE_ENV?.toLowerCase();return t==="production"||t==="prod"}getDefaultLevel(t){return t?"warn":"debug"}getDefaultColorizeValue(t){return t!==void 0?t:!this.isProductionEnvironment()}getDefaultJson(t){return t}getDefaultTimestamp(t){return!0}getDefaultTransports(t){return t?[new f,new v({path:"./logs/app.log"})]:[new f]}getDefaultAsyncMode(t){return t}initTransports(t,e){let s=[];for(let o of t)if(this.isLegacyTransportOptions(o)){let r=o;if(r.type==="console"){let n=new f({colorize:r.options?.colorize??e});s.push(n)}else if(r.type==="file"){if(r.options?.path){let n={path:r.options.path};r.options.maxSize!==void 0&&(n.maxSize=r.options.maxSize),r.options.maxFiles!==void 0&&(n.maxFiles=r.options.maxFiles),r.options.compression!==void 0&&(n.compression=r.options.compression),r.options.batchInterval!==void 0&&(n.batchInterval=r.options.batchInterval),r.options.compressOldFiles!==void 0&&(n.compressOldFiles=r.options.compressOldFiles);let p=new v(n);s.push(p)}}else r.type==="custom"&&r.instance&&s.push(r.instance)}else this.isTransport(o)&&s.push(o);return s}isLegacyTransportOptions(t){return typeof t=="object"&&t!==null&&"type"in t}isTransport(t){return t&&typeof t.write=="function"&&(typeof t.writeAsync=="function"||t.writeAsync===void 0)}shouldLog(t){let e=this.getLevelPriority(this.level);return this.getLevelPriority(t)>=e}getLevelPriority(t){if(l.LEVEL_PRIORITIES.hasOwnProperty(t))return l.LEVEL_PRIORITIES[t];if(this.customLevels&&t in this.customLevels){let e=this.customLevels[t];return e!==void 0?e:999}return 999}log(t,e,s){if(this.shouldLog(t)&&t!=="silent")if(this.asyncMode)this.logAsyncDirect(t,e,s);else{let o=new Date,r;this.context&&Object.keys(this.context).length>0?s?r={...this.context,...s}:r=this.context:s&&(r=s);let n={level:t,message:e,timestamp:o,metadata:r&&Object.keys(r).length>0?r:void 0,prefix:this.prefix};for(let p of this.transports)p.write(n,this.formatter)}}logAsyncDirect(t,e,s){if(!this.shouldLog(t)||t==="silent")return;let o=new Date,r;this.context&&Object.keys(this.context).length>0?s?r={...this.context,...s}:r=this.context:s&&(r=s);let n={level:t,message:e,timestamp:o,metadata:r&&Object.keys(r).length>0?r:void 0,prefix:this.prefix};for(let p of this.transports)p.writeAsync?p.writeAsync(n,this.formatter).catch(c=>{console.error("Error during async logging:",c)}):setImmediate(()=>{p.write(n,this.formatter)})}debug(t,e){this.log("debug",t,e)}info(t,e){this.log("info",t,e)}warn(t,e){this.log("warn",t,e)}error(t,e){this.log("error",t,e)}silent(t,e){this.log("silent",t,e)}boring(t,e){this.log("boring",t,e)}logWithLevel(t,e,s){this.log(t,e,s)}setLevel(t){this.level=t}setFormat(t){this.formatter.setJson(t==="json")}setAsyncMode(t){this.asyncMode=t}addTransport(t){this.transports.push(t)}getTimestampSetting(){return this.timestamp}static get global(){return l._global||(l._global=new l),l._global}createChild(t={}){return new l({...t,parent:this})}startTimer(t){let{Timer:e}=(D(),j(z));return new e(t,s=>this.info(s))}};var xt=F;export{f as ConsoleTransport,v as FileTransport,T as HttpTransport,F as Logger,q as consoleT,xt as default,J as fileT,Q as httpT};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ConsoleTransport, ConsoleTransportOptions } from "./ConsoleTransport";
|
|
2
|
-
import { FileTransport, FileTransportOptions } from "./FileTransport";
|
|
3
|
-
import { HttpTransport, HttpTransportOptions } from "./HttpTransport";
|
|
4
|
-
export * from "./Transport";
|
|
5
|
-
export * from "./ConsoleTransport";
|
|
6
|
-
export * from "./FileTransport";
|
|
7
|
-
export * from "./HttpTransport";
|
|
8
|
-
/**
|
|
9
|
-
* Create a ConsoleTransport instance configured with the given options.
|
|
10
|
-
*
|
|
11
|
-
* @param options - Configuration options for the console transport
|
|
12
|
-
* @returns A `ConsoleTransport` instance
|
|
13
|
-
*/
|
|
14
|
-
export declare function consoleT(options?: ConsoleTransportOptions): ConsoleTransport;
|
|
15
|
-
/**
|
|
16
|
-
* Create a FileTransport configured with the provided options.
|
|
17
|
-
*
|
|
18
|
-
* @param options - Options to configure the FileTransport
|
|
19
|
-
* @returns A new `FileTransport` instance configured according to `options`
|
|
20
|
-
*/
|
|
21
|
-
export declare function fileT(options: FileTransportOptions): FileTransport;
|
|
22
|
-
/**
|
|
23
|
-
* Creates an HttpTransport using the provided configuration.
|
|
24
|
-
*
|
|
25
|
-
* @param options - Configuration options for the HttpTransport
|
|
26
|
-
* @returns The constructed `HttpTransport` instance
|
|
27
|
-
*/
|
|
28
|
-
export declare function httpT(options: HttpTransportOptions): HttpTransport;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|