@nexload-sdk/logger 3.0.0 → 3.1.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/dist/index.cjs CHANGED
@@ -1,14 +1,439 @@
1
- // @nexload-sdk/logger v2.5.0 (build 2025-11-24T14:06:51.909Z)
2
- "use strict";var te=Object.create;var L=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var se=(e,t)=>()=>(e&&(t=e(e=0)),t);var O=(e,t)=>{for(var r in t)L(e,r,{get:t[r],enumerable:!0})},N=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of oe(t))!ie.call(e,i)&&i!==r&&L(e,i,{get:()=>t[i],enumerable:!(n=re(t,i))||n.enumerable});return e};var ce=(e,t,r)=>(r=e!=null?te(ne(e)):{},N(t||!e||!e.__esModule?L(r,"default",{value:e,enumerable:!0}):r,e)),ae=e=>N(L({},"__esModule",{value:!0}),e);var J={};O(J,{test:()=>xe});async function xe(e){let t=Math.floor(Math.random()*1e4);e.trace({pid:t,memory:80},"Process started, initializing modules...");let r={db:"mongo:27017",timeout:5e3,retries:3};e.debug({config:r},"Configuration loaded successfully"),e.info({dbHost:r.db,poolSize:10},"Attempting to connect to Database..."),await new Promise(s=>setTimeout(s,100)),e.success({latency_ms:45,status:"connected"},"Database connection established");let n=[{id:101,amount:500,user:"ali"},{id:102,amount:0,user:"bot"},{id:103,amount:12e3,user:"sara"}];e.info({batchSize:n.length},"Starting batch order processing");for(let s of n){if(e.trace({orderId:s.id},"Processing order item"),s.amount<=0){e.warn({orderId:s.id,userId:s.user,amount:s.amount},"Skipping invalid order amount");continue}e.info({orderId:s.id,transactionId:`tx_${Math.random().toString(36).substring(7)}`},"Order processed")}try{Fe()}catch(s){e.error({errorName:s.name,errorMessage:s.message,stack:s.stack,failedModule:"PaymentGateway"},"Transaction failed unexpectedly")}let i=80,c=1024*1024*500;i<c&&e.fatal({usage:i,limit:c,action:"graceful_shutdown"},"CRITICAL: Memory leak detected, shutting down service!")}function Fe(){throw new Error("Connection ECONNREFUSED 127.0.0.1:8080")}var K=se(()=>{"use strict"});var Te={};O(Te,{NexloadLogger:()=>h,default:()=>Ie,isBrowser:()=>l,isNode:()=>p,levelPriorities:()=>E});module.exports=ae(Te);var l=()=>typeof window<"u"&&typeof document<"u",p=()=>typeof process<"u",E={FATAL:70,ERROR:60,WARN:50,SUCCESS:40,INFO:30,DEBUG:20,TRACE:10};var h=class{constructor(t,r,n){this.name=t;this.level=r;this.renderer=n;this.threshold=E[r],this.name=this.name.toUpperCase()}threshold;dispatch(t,r,n){if(E[t]<this.threshold)return;let i={...r,name:this.name,level:t,time:Date.now()};return n&&(i.message=n),l()?this.renderer.browser(i):p()?this.renderer.node(i):console.log(i)}trace(t,r){this.dispatch("TRACE",t,r)}debug(t,r){this.dispatch("DEBUG",t,r)}info(t,r){this.dispatch("INFO",t,r)}success(t,r){this.dispatch("SUCCESS",t,r)}warn(t,r){this.dispatch("WARN",t,r)}error(t,r){this.dispatch("ERROR",t,r)}fatal(t,r){this.dispatch("FATAL",t,r)}};var le="color:inherit;font-weight:inherit;",de="color:#808080cc;font-weight:100;",ge="font-weight:900;",ue={TRACE:"color: #808080;",DEBUG:"color: #2980b9;",INFO:"color: #009688;",SUCCESS:"color: #27ae60;",WARN:"color: #d35400;",ERROR:"color: #c0392b;",FATAL:"color: #8e44ad;"},me={TRACE:"\u203A",DEBUG:"\u2022",INFO:"\u2139",SUCCESS:"\u2714",WARN:"\u26A0",ERROR:"\u2717",FATAL:"\u271D"},x=e=>{let{level:t,time:r,message:n,name:i,pid:c,...s}=e,a=me[t],u=ue[t];console.log(`%c[%s] %c%s %c%s%c - %s
3
- %o`,u,a,u+ge,t.padEnd(7),de,i.padEnd(6),le,n,s)};var F=e=>{let{level:t,time:r,message:n,name:i,pid:c,...s}=e,a=i.padEnd(6),y=`${t.padEnd(5)} ${a} \u2014 ${n}`;switch(t){case"WARN":console.warn(y,s);case"ERROR":console.error(y,s);break;default:break}};var B=ce(require("tty"),1),{env:g={},argv:T=[],platform:be=""}=typeof process>"u"?{}:process,pe="NO_COLOR"in g||T.includes("--no-color"),he="FORCE_COLOR"in g||T.includes("--color"),fe=be==="win32",k=g.TERM==="dumb",Re=B&&B.isatty&&B.isatty(1)&&g.TERM&&!k,ye="CI"in g&&("GITHUB_ACTIONS"in g||"GITLAB_CI"in g||"CIRCLECI"in g),Le=!pe&&(he||fe&&!k||Re||ye),$=(e,t,r,n,i=t.substring(0,e)+n,c=t.substring(e+r.length),s=c.indexOf(r))=>i+(s<0?c:$(s,c,r,n)),Ee=(e,t,r,n,i)=>e<0?r+t+n:r+$(e,t,n,i)+n,Be=(e,t,r=e,n=e.length+1)=>i=>i||!(i===""||i===void 0)?Ee((""+i).indexOf(t,n),i,e,t,r):"",o=(e,t,r)=>Be(`\x1B[${e}m`,`\x1B[${t}m`,r),I={reset:o(0,0),bold:o(1,22,"\x1B[22m\x1B[1m"),dim:o(2,22,"\x1B[22m\x1B[2m"),italic:o(3,23),underline:o(4,24),inverse:o(7,27),hidden:o(8,28),strikethrough:o(9,29),black:o(30,39),red:o(31,39),green:o(32,39),yellow:o(33,39),blue:o(34,39),magenta:o(35,39),cyan:o(36,39),white:o(37,39),gray:o(90,39),bgBlack:o(40,49),bgRed:o(41,49),bgGreen:o(42,49),bgYellow:o(43,49),bgBlue:o(44,49),bgMagenta:o(45,49),bgCyan:o(46,49),bgWhite:o(47,49),blackBright:o(90,39),redBright:o(91,39),greenBright:o(92,39),yellowBright:o(93,39),blueBright:o(94,39),magentaBright:o(95,39),cyanBright:o(96,39),whiteBright:o(97,39),bgBlackBright:o(100,49),bgRedBright:o(101,49),bgGreenBright:o(102,49),bgYellowBright:o(103,49),bgBlueBright:o(104,49),bgMagentaBright:o(105,49),bgCyanBright:o(106,49),bgWhiteBright:o(107,49)},we=({useColor:e=Le}={})=>e?I:Object.keys(I).reduce((t,r)=>({...t,[r]:String}),{}),{reset:Me,bold:m,dim:f,italic:_e,underline:Ve,inverse:ze,hidden:He,strikethrough:Ye,black:Je,red:G,green:w,yellow:S,blue:Ke,magenta:U,cyan:j,white:D,gray:b,bgBlack:qe,bgRed:Qe,bgGreen:Xe,bgYellow:Ze,bgBlue:et,bgMagenta:tt,bgCyan:rt,bgWhite:ot,blackBright:nt,redBright:P,greenBright:it,yellowBright:st,blueBright:ct,magentaBright:W,cyanBright:M,whiteBright:at,bgBlackBright:lt,bgRedBright:dt,bgGreenBright:gt,bgYellowBright:ut,bgBlueBright:mt,bgMagentaBright:bt,bgCyanBright:pt,bgWhiteBright:ht}=we();var _=e=>{if(e===null)return m(b("null"));if(e===void 0)return m(b("undefined"));switch(typeof e){case"string":return w(`"${e}"`);case"number":return S(String(e));case"boolean":return U(String(e));default:return D(String(e))}};function C(e,t=0){let r=" ".repeat(t);if(e===null||typeof e!="object")return _(e);let n="";for(let[i,c]of Object.entries(e)){let s=j(i);if(typeof c=="string"&&c.includes(`
4
- `)){n+=`${r}${s}: |
5
- `;let a=c.split(`
6
- `);n+=a.map(u=>`${r} ${f(u)}`).join(`
7
- `),n+=`
8
- `;continue}if(typeof c=="object"&&c!==null){Object.keys(c).length===0?n+=`${r}${s}: ${b("{}")}
9
- `:(n+=`${r}${s}:
10
- `,n+=C(c,t+1));continue}n+=`${r}${s}: ${_(c)}
11
- `}return n}var V={TRACE:b,DEBUG:W,INFO:M,SUCCESS:w,WARN:S,ERROR:P,FATAL:G},Se={TRACE:"\u203A",DEBUG:"\u2022",INFO:"\u2139",SUCCESS:"\u2714",WARN:"\u26A0",ERROR:"\u2717",FATAL:"\u271D"},R=e=>e==null||typeof e!="object"||Object.keys(e).length===0?[]:[`
12
- `+C(e,2)],Ce=e=>{let t=Se[e],r=V[e];return r("["+t+"]")},z=e=>{var A;let t=typeof process<"u"?(A=process==null?void 0:process.stdout)==null?void 0:A.columns:80,{level:r,time:n,message:i,name:c,pid:s,...a}=e,u=new Date(n??void 0),y=V[r],Q=Ce(r),X=f(m(c.padEnd(6))),Z=y(m(r.padEnd(7))),v=f(u.toTimeString().slice(0,8)),d=`${Q} ${Z} ${X} \u2014 ${i}`,ee=Math.max(1,t-d.length-v.length);switch(d=d+" ".repeat(ee)+v,r){case"INFO":console.info(d,...R(a));break;case"WARN":console.warn(d,...R(a));break;case"ERROR":console.error(d,...R(a));break;case"DEBUG":console.debug(d,...R(a));break;default:console.log(d,...R(a));break}};var H=e=>{l()||!p()||process.stdout.write(JSON.stringify(e)+`
13
- `)};var ve=()=>(l()?localStorage.getItem("$SERVICE_NAME"):process.env.SERVICE_NAME)||"unknown",Ae=()=>(l()?localStorage.getItem("$LOG_LEVEL"):process.env.LOG_LEVEL)||"WARN",Oe=()=>l()?localStorage.getItem("$DEBUG")!=="1":process.env.DEBUG==="true"?!1:process.env.NODE_ENV==="production",Ne=()=>Oe()?{browser:F.bind(null),node:H.bind(null)}:{browser:x.bind(null),node:z.bind(null)},Y=()=>new h(ve(),Ae(),Ne());var q=Y();new Promise(async()=>{(await Promise.resolve().then(()=>(K(),J))).test(q)});var Ie=q;0&&(module.exports={NexloadLogger,isBrowser,isNode,levelPriorities});
1
+ // @nexload-sdk/logger v3.1.0 (build 2025-12-16T12:33:20.959Z)
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ NexloadLogger: () => NexloadLogger,
35
+ default: () => index_default,
36
+ isBrowser: () => isBrowser,
37
+ isNode: () => isNode,
38
+ levelPriorities: () => levelPriorities
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/types.ts
43
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
44
+ var isNode = () => typeof process !== "undefined";
45
+ var levelPriorities = {
46
+ FATAL: 70,
47
+ ERROR: 60,
48
+ WARN: 50,
49
+ SUCCESS: 40,
50
+ INFO: 30,
51
+ DEBUG: 20,
52
+ TRACE: 10
53
+ };
54
+
55
+ // src/logger.ts
56
+ var NexloadLogger = class _NexloadLogger {
57
+ constructor(name, level, renderer, baseObject = {}) {
58
+ this.name = name;
59
+ this.level = level;
60
+ this.renderer = renderer;
61
+ this.baseObject = baseObject;
62
+ this.threshold = levelPriorities[level];
63
+ this.name = this.name.toUpperCase();
64
+ }
65
+ threshold;
66
+ dispatch(level, obj, message) {
67
+ if (levelPriorities[level] < this.threshold) return;
68
+ const payload = {
69
+ ...this.baseObject,
70
+ ...obj,
71
+ name: this.name,
72
+ level,
73
+ time: Date.now()
74
+ };
75
+ if (message) {
76
+ payload.message = message;
77
+ }
78
+ if (isBrowser()) return this.renderer.browser(payload);
79
+ if (isNode()) return this.renderer.node(payload);
80
+ return console.log(payload);
81
+ }
82
+ child(obj = {}) {
83
+ return new _NexloadLogger(this.name, this.level, this.renderer, {
84
+ ...this.baseObject,
85
+ ...obj
86
+ });
87
+ }
88
+ trace(obj, msg) {
89
+ this.dispatch("TRACE", obj, msg);
90
+ }
91
+ debug(obj, msg) {
92
+ this.dispatch("DEBUG", obj, msg);
93
+ }
94
+ info(obj, msg) {
95
+ this.dispatch("INFO", obj, msg);
96
+ }
97
+ success(obj, msg) {
98
+ this.dispatch("SUCCESS", obj, msg);
99
+ }
100
+ warn(obj, msg) {
101
+ this.dispatch("WARN", obj, msg);
102
+ }
103
+ error(obj, msg) {
104
+ this.dispatch("ERROR", obj, msg);
105
+ }
106
+ fatal(obj, msg) {
107
+ this.dispatch("FATAL", obj, msg);
108
+ }
109
+ };
110
+
111
+ // src/renderers/browser-pretty.ts
112
+ var reset = "color:inherit;font-weight:inherit;";
113
+ var dimStyle = "color:#808080cc;font-weight:100;";
114
+ var boldStyle = "font-weight:900;";
115
+ var levelColors = {
116
+ TRACE: "color: #808080;",
117
+ DEBUG: "color: #2980b9;",
118
+ INFO: "color: #009688;",
119
+ SUCCESS: "color: #27ae60;",
120
+ WARN: "color: #d35400;",
121
+ ERROR: "color: #c0392b;",
122
+ FATAL: "color: #8e44ad;"
123
+ };
124
+ var levelSymbols = {
125
+ TRACE: "\u203A",
126
+ DEBUG: "\u2022",
127
+ INFO: "\u2139",
128
+ SUCCESS: "\u2714",
129
+ WARN: "\u26A0",
130
+ ERROR: "\u2717",
131
+ FATAL: "\u271D"
132
+ };
133
+ var browserPrettyRenderer = (line) => {
134
+ const { level, time, message, name, pid, ...extras } = line;
135
+ const symbol = levelSymbols[level];
136
+ const colorStyle = levelColors[level];
137
+ console.log(
138
+ `%c[%s] %c%s %c%s%c - %s
139
+ %o`,
140
+ colorStyle,
141
+ symbol,
142
+ colorStyle + boldStyle,
143
+ level.padEnd(7),
144
+ dimStyle,
145
+ name.padEnd(6),
146
+ reset,
147
+ message,
148
+ extras
149
+ );
150
+ };
151
+
152
+ // src/renderers/browser-pure.ts
153
+ var browserPureRenderer = (line) => {
154
+ const { level, time, message, name, pid, ...extras } = line;
155
+ const nameStr = name.padEnd(6);
156
+ const levelStr = level.padEnd(5);
157
+ const lineStr = `${levelStr} ${nameStr} \u2014 ${message}`;
158
+ switch (level) {
159
+ case "WARN":
160
+ console.warn(lineStr, extras);
161
+ case "ERROR":
162
+ console.error(lineStr, extras);
163
+ break;
164
+ default:
165
+ break;
166
+ }
167
+ };
168
+
169
+ // ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
170
+ var tty = __toESM(require("tty"), 1);
171
+ var {
172
+ env = {},
173
+ argv = [],
174
+ platform = ""
175
+ } = typeof process === "undefined" ? {} : process;
176
+ var isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
177
+ var isForced = "FORCE_COLOR" in env || argv.includes("--color");
178
+ var isWindows = platform === "win32";
179
+ var isDumbTerminal = env.TERM === "dumb";
180
+ var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
181
+ var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
182
+ var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
183
+ var replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
184
+ var clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
185
+ var filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === void 0) ? clearBleed(
186
+ ("" + string).indexOf(close, at),
187
+ string,
188
+ open,
189
+ close,
190
+ replace
191
+ ) : "";
192
+ var init = (open, close, replace) => filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
193
+ var colors = {
194
+ reset: init(0, 0),
195
+ bold: init(1, 22, "\x1B[22m\x1B[1m"),
196
+ dim: init(2, 22, "\x1B[22m\x1B[2m"),
197
+ italic: init(3, 23),
198
+ underline: init(4, 24),
199
+ inverse: init(7, 27),
200
+ hidden: init(8, 28),
201
+ strikethrough: init(9, 29),
202
+ black: init(30, 39),
203
+ red: init(31, 39),
204
+ green: init(32, 39),
205
+ yellow: init(33, 39),
206
+ blue: init(34, 39),
207
+ magenta: init(35, 39),
208
+ cyan: init(36, 39),
209
+ white: init(37, 39),
210
+ gray: init(90, 39),
211
+ bgBlack: init(40, 49),
212
+ bgRed: init(41, 49),
213
+ bgGreen: init(42, 49),
214
+ bgYellow: init(43, 49),
215
+ bgBlue: init(44, 49),
216
+ bgMagenta: init(45, 49),
217
+ bgCyan: init(46, 49),
218
+ bgWhite: init(47, 49),
219
+ blackBright: init(90, 39),
220
+ redBright: init(91, 39),
221
+ greenBright: init(92, 39),
222
+ yellowBright: init(93, 39),
223
+ blueBright: init(94, 39),
224
+ magentaBright: init(95, 39),
225
+ cyanBright: init(96, 39),
226
+ whiteBright: init(97, 39),
227
+ bgBlackBright: init(100, 49),
228
+ bgRedBright: init(101, 49),
229
+ bgGreenBright: init(102, 49),
230
+ bgYellowBright: init(103, 49),
231
+ bgBlueBright: init(104, 49),
232
+ bgMagentaBright: init(105, 49),
233
+ bgCyanBright: init(106, 49),
234
+ bgWhiteBright: init(107, 49)
235
+ };
236
+ var createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce(
237
+ (colors2, key) => ({ ...colors2, [key]: String }),
238
+ {}
239
+ );
240
+ var {
241
+ reset: reset2,
242
+ bold,
243
+ dim,
244
+ italic,
245
+ underline,
246
+ inverse,
247
+ hidden,
248
+ strikethrough,
249
+ black,
250
+ red,
251
+ green,
252
+ yellow,
253
+ blue,
254
+ magenta,
255
+ cyan,
256
+ white,
257
+ gray,
258
+ bgBlack,
259
+ bgRed,
260
+ bgGreen,
261
+ bgYellow,
262
+ bgBlue,
263
+ bgMagenta,
264
+ bgCyan,
265
+ bgWhite,
266
+ blackBright,
267
+ redBright,
268
+ greenBright,
269
+ yellowBright,
270
+ blueBright,
271
+ magentaBright,
272
+ cyanBright,
273
+ whiteBright,
274
+ bgBlackBright,
275
+ bgRedBright,
276
+ bgGreenBright,
277
+ bgYellowBright,
278
+ bgBlueBright,
279
+ bgMagentaBright,
280
+ bgCyanBright,
281
+ bgWhiteBright
282
+ } = createColors();
283
+
284
+ // src/utils/json-humanize.ts
285
+ var styleValue = (value) => {
286
+ if (value === null) return bold(gray("null"));
287
+ if (value === void 0) return bold(gray("undefined"));
288
+ switch (typeof value) {
289
+ case "string":
290
+ return green(`"${value}"`);
291
+ // رشته‌ها سبز
292
+ case "number":
293
+ return yellow(String(value));
294
+ // اعداد زرد
295
+ case "boolean":
296
+ return magenta(String(value));
297
+ // بولین‌ها بنفش
298
+ default:
299
+ return white(String(value));
300
+ }
301
+ };
302
+ function jsonHumanize(data, indentLevel = 0) {
303
+ const indent = " ".repeat(indentLevel);
304
+ if (data === null || typeof data !== "object") {
305
+ return styleValue(data);
306
+ }
307
+ let output = "";
308
+ for (const [key, value] of Object.entries(data)) {
309
+ const coloredKey = cyan(key);
310
+ if (typeof value === "string" && value.includes("\n")) {
311
+ output += `${indent}${coloredKey}: |
312
+ `;
313
+ const lines = value.split("\n");
314
+ output += lines.map((line) => `${indent} ${dim(line)}`).join("\n");
315
+ output += "\n";
316
+ continue;
317
+ }
318
+ if (typeof value === "object" && value !== null) {
319
+ if (Object.keys(value).length === 0) {
320
+ output += `${indent}${coloredKey}: ${gray("{}")}
321
+ `;
322
+ } else {
323
+ output += `${indent}${coloredKey}:
324
+ `;
325
+ output += jsonHumanize(value, indentLevel + 1);
326
+ }
327
+ continue;
328
+ }
329
+ output += `${indent}${coloredKey}: ${styleValue(value)}
330
+ `;
331
+ }
332
+ return output;
333
+ }
334
+
335
+ // src/renderers/node-pretty.ts
336
+ var levelColors2 = {
337
+ TRACE: gray,
338
+ DEBUG: magentaBright,
339
+ INFO: cyanBright,
340
+ SUCCESS: green,
341
+ WARN: yellow,
342
+ ERROR: redBright,
343
+ FATAL: red
344
+ };
345
+ var levelSymbols2 = {
346
+ TRACE: "\u203A",
347
+ DEBUG: "\u2022",
348
+ INFO: "\u2139",
349
+ SUCCESS: "\u2714",
350
+ WARN: "\u26A0",
351
+ ERROR: "\u2717",
352
+ FATAL: "\u271D"
353
+ };
354
+ var extrasFromatter = (extras) => {
355
+ if (extras == null || typeof extras !== "object" || Object.keys(extras).length === 0)
356
+ return [];
357
+ return ["\n" + jsonHumanize(extras, 2)];
358
+ };
359
+ var levelToSymbol = (level) => {
360
+ const symbol = levelSymbols2[level];
361
+ const color = levelColors2[level];
362
+ return color("[" + symbol + "]");
363
+ };
364
+ var nodePrettyRenderer = (line) => {
365
+ var _a;
366
+ const columns = typeof process !== "undefined" ? (_a = process == null ? void 0 : process.stdout) == null ? void 0 : _a.columns : 80;
367
+ const { level, time, message, name, pid, ...extras } = line;
368
+ const dateTime = new Date(time ?? void 0);
369
+ const levelColor = levelColors2[level];
370
+ const symbol = levelToSymbol(level);
371
+ const nameStr = dim(bold(name.padEnd(6)));
372
+ const levelStr = levelColor(bold(level.padEnd(7)));
373
+ const timeStr = dim(dateTime.toTimeString().slice(0, 8));
374
+ let lineStr = `${symbol} ${levelStr} ${nameStr} \u2014 ${message}`;
375
+ const spaceCount = Math.max(1, columns - lineStr.length - timeStr.length);
376
+ lineStr = lineStr + " ".repeat(spaceCount) + timeStr;
377
+ switch (level) {
378
+ case "INFO":
379
+ console.info(lineStr, ...extrasFromatter(extras));
380
+ break;
381
+ case "WARN":
382
+ console.warn(lineStr, ...extrasFromatter(extras));
383
+ break;
384
+ case "ERROR":
385
+ console.error(lineStr, ...extrasFromatter(extras));
386
+ break;
387
+ case "DEBUG":
388
+ console.debug(lineStr, ...extrasFromatter(extras));
389
+ break;
390
+ default:
391
+ console.log(lineStr, ...extrasFromatter(extras));
392
+ break;
393
+ }
394
+ };
395
+
396
+ // src/renderers/node-pure-json.ts
397
+ var nodePureJsonRenderer = (line) => {
398
+ if (isBrowser() || !isNode()) return;
399
+ process.stdout.write(JSON.stringify(line) + "\n");
400
+ };
401
+
402
+ // src/utils/create-global.ts
403
+ var getServiceName = () => (isBrowser() ? localStorage.getItem("$SERVICE_NAME") : process.env.SERVICE_NAME) || "unknown";
404
+ var getLogLevel = () => (isBrowser() ? localStorage.getItem("$LOG_LEVEL") : process.env.LOG_LEVEL) || "WARN";
405
+ var getProduction = () => {
406
+ if (isBrowser()) {
407
+ return localStorage.getItem("$DEBUG") !== "1";
408
+ }
409
+ if (process.env.DEBUG === "true") {
410
+ return false;
411
+ }
412
+ return process.env.NODE_ENV === "production";
413
+ };
414
+ var getRenderer = () => {
415
+ const isProduction = getProduction();
416
+ if (isProduction) {
417
+ return {
418
+ browser: browserPureRenderer.bind(null),
419
+ node: nodePureJsonRenderer.bind(null)
420
+ };
421
+ }
422
+ return {
423
+ browser: browserPrettyRenderer.bind(null),
424
+ node: nodePrettyRenderer.bind(null)
425
+ };
426
+ };
427
+ var createGlobalLogger = () => new NexloadLogger(getServiceName(), getLogLevel(), getRenderer());
428
+
429
+ // src/index.ts
430
+ var logger = createGlobalLogger();
431
+ var index_default = logger;
432
+ // Annotate the CommonJS export names for ESM import in node:
433
+ 0 && (module.exports = {
434
+ NexloadLogger,
435
+ isBrowser,
436
+ isNode,
437
+ levelPriorities
438
+ });
14
439
  //# sourceMappingURL=index.cjs.map