@putkoff/abstract-logger 0.0.35 โ†’ 0.0.37

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.
Files changed (47) hide show
  1. package/dist/cjs/index.js +372 -257
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/config.d.ts +4 -0
  4. package/dist/cjs/types/imports/constants.d.ts +8 -0
  5. package/dist/cjs/types/imports/functions.d.ts +16 -0
  6. package/dist/cjs/types/imports/index.d.ts +5 -0
  7. package/dist/cjs/types/imports/init_imports.d.ts +1 -0
  8. package/dist/cjs/types/imports/nodeLogger.d.ts +3 -0
  9. package/dist/cjs/types/imports/utils/detect.d.ts +10 -0
  10. package/dist/cjs/types/imports/utils/index.d.ts +2 -0
  11. package/dist/cjs/types/imports/utils/utils.d.ts +8 -0
  12. package/dist/cjs/types/index.d.ts +1 -1
  13. package/dist/cjs/types/logger/blocker.d.ts +4 -0
  14. package/dist/cjs/types/logger/logger.d.ts +1 -18
  15. package/dist/cjs/types/types/index.d.ts +1 -0
  16. package/dist/cjs/types/types/types.d.ts +10 -0
  17. package/dist/esm/index.js +360 -258
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/types/config.d.ts +4 -0
  20. package/dist/esm/types/imports/constants.d.ts +8 -0
  21. package/dist/esm/types/imports/functions.d.ts +16 -0
  22. package/dist/esm/types/imports/index.d.ts +5 -0
  23. package/dist/esm/types/imports/init_imports.d.ts +1 -0
  24. package/dist/esm/types/imports/nodeLogger.d.ts +3 -0
  25. package/dist/esm/types/imports/utils/detect.d.ts +10 -0
  26. package/dist/esm/types/imports/utils/index.d.ts +2 -0
  27. package/dist/esm/types/imports/utils/utils.d.ts +8 -0
  28. package/dist/esm/types/index.d.ts +1 -1
  29. package/dist/esm/types/logger/blocker.d.ts +4 -0
  30. package/dist/esm/types/logger/logger.d.ts +1 -18
  31. package/dist/esm/types/types/index.d.ts +1 -0
  32. package/dist/esm/types/types/types.d.ts +10 -0
  33. package/dist/types/config.d.ts +4 -0
  34. package/dist/types/imports/constants.d.ts +8 -0
  35. package/dist/types/imports/functions.d.ts +16 -0
  36. package/dist/types/imports/index.d.ts +5 -0
  37. package/dist/types/imports/init_imports.d.ts +1 -0
  38. package/dist/types/imports/nodeLogger.d.ts +3 -0
  39. package/dist/types/imports/utils/detect.d.ts +10 -0
  40. package/dist/types/imports/utils/index.d.ts +2 -0
  41. package/dist/types/imports/utils/utils.d.ts +8 -0
  42. package/dist/types/index.d.ts +51 -11
  43. package/dist/types/logger/blocker.d.ts +4 -0
  44. package/dist/types/logger/logger.d.ts +1 -18
  45. package/dist/types/types/index.d.ts +1 -0
  46. package/dist/types/types/types.d.ts +10 -0
  47. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -12,7 +12,210 @@ var require$$1 = require('tty');
12
12
  var require$$1$1 = require('string_decoder');
13
13
  var require$$0$7 = require('http');
14
14
  var require$$1$3 = require('https');
15
- require('dotenv/config');
15
+
16
+ /* ------------------------------------------------------------------ */
17
+ /* Stack inspection */
18
+ /* ------------------------------------------------------------------ */
19
+ function padRight(str, width) {
20
+ return str.length >= width ? str : str + " ".repeat(width - str.length);
21
+ }
22
+ function padLeft(str, width) {
23
+ return str.length >= width ? str : " ".repeat(width - str.length) + str;
24
+ }
25
+ /**
26
+ * Normalizes inputs by treating "unknown" and empty values as null.
27
+ * Returns "unknown" ONLY if all inputs are invalid.
28
+ */
29
+ function resolveValue(...values) {
30
+ let sawInput = false;
31
+ for (const value of values) {
32
+ if (value === undefined || value === null)
33
+ continue;
34
+ sawInput = true;
35
+ if (typeof value === "string") {
36
+ const v = value.trim();
37
+ if (!v || v.toLowerCase() === "unknown")
38
+ continue;
39
+ return value;
40
+ }
41
+ return value;
42
+ }
43
+ return sawInput ? "unknown" : "unknown";
44
+ }
45
+ function parseList(value) {
46
+ return value
47
+ ? value.split(",").map(s => s.trim()).filter(Boolean)
48
+ : [];
49
+ }
50
+
51
+ /** ---------------------------------------------------------
52
+ * Detect Environment
53
+ * --------------------------------------------------------- */
54
+ const IS_BROWSER = typeof window !== "undefined" &&
55
+ typeof window.document !== "undefined";
56
+ const IS_NODE = typeof process !== "undefined" &&
57
+ process.release?.name === "node";
58
+ /* ------------------------------------------------------------------ */
59
+ /* Stack inspection */
60
+ /* ------------------------------------------------------------------ */
61
+ function extractFile(frame) {
62
+ // file:///path/to/file.ts:line:col
63
+ const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
64
+ if (esmMatch)
65
+ return esmMatch[1];
66
+ // (path/to/file.ts:line:col)
67
+ const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
68
+ if (cjsMatch)
69
+ return cjsMatch[1];
70
+ // at path/to/file.ts:line:col
71
+ const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
72
+ if (bareMatch)
73
+ return bareMatch[1];
74
+ return "unknown";
75
+ }
76
+ function getCallerInfo(func) {
77
+ if (!IS_NODE) {
78
+ return { functionName: "browser", file: "browser" };
79
+ }
80
+ const obj = {};
81
+ Error.captureStackTrace(obj, func);
82
+ const stack = obj.stack?.split("\n") ?? [];
83
+ const frame = stack
84
+ .slice(1)
85
+ .find((line) => !line.includes("node:internal") &&
86
+ !line.includes("processTicksAndRejections"));
87
+ if (!frame) {
88
+ return { functionName: "unknown", file: "unknown" };
89
+ }
90
+ const fnMatch = frame.match(/at\s+async\s+([^\s(]+)/) ||
91
+ frame.match(/at\s+([^\s(]+)/);
92
+ return {
93
+ functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
94
+ ? fnMatch[1]
95
+ : "unknown",
96
+ file: extractFile(frame),
97
+ };
98
+ }
99
+
100
+ const activityEmojiMap = {
101
+ emitting: "๐Ÿ“ค",
102
+ ingesting: "๐Ÿ“ฅ",
103
+ streaming: "๐ŸŒŠ",
104
+ forwarding: "โžก๏ธ",
105
+ receiving: "๐Ÿ“ก",
106
+ relaying: "๐Ÿ”",
107
+ syncing: "๐Ÿ”„",
108
+ buffering: "โณ",
109
+ batching: "๐Ÿ“ฆ",
110
+ dispatching: "๐Ÿš€",
111
+ settings: "โš™๏ธ",
112
+ computing: "๐Ÿง ",
113
+ running: "๐Ÿƒ",
114
+ working: "๐Ÿ”ง",
115
+ building: "๐Ÿ—๏ธ",
116
+ compiling: "๐Ÿงฉ",
117
+ crunching: "๐Ÿงฎ",
118
+ optimizing: "๐Ÿ“ˆ",
119
+ queued: "๐Ÿ•’",
120
+ waiting: "โณ",
121
+ active: "โ–ถ๏ธ",
122
+ paused: "โธ๏ธ",
123
+ sleeping: "๐Ÿ’ค",
124
+ resumed: "๐Ÿ”„",
125
+ completed: "โœ…",
126
+ cancelled: "โŒ",
127
+ expired: "โŒ›",
128
+ warning: "โš ๏ธ",
129
+ error: "โŒ",
130
+ critical: "๐Ÿšจ",
131
+ retrying: "๐Ÿ”",
132
+ skipped: "โญ๏ธ",
133
+ fallback: "๐Ÿ›Ÿ",
134
+ degraded: "๐Ÿ“‰",
135
+ saved: "๐Ÿ’พ",
136
+ loading: "๐Ÿ“‚",
137
+ exporting: "๐Ÿ“ค",
138
+ importing: "๐Ÿ“ฅ",
139
+ archived: "๐Ÿ—„๏ธ",
140
+ deleted: "๐Ÿ—‘๏ธ",
141
+ cached: "๐ŸงŠ",
142
+ persisted: "๐Ÿ“Œ",
143
+ locked: "๐Ÿ”’",
144
+ unlocked: "๐Ÿ”“",
145
+ secure: "๐Ÿ›ก๏ธ",
146
+ insecure: "โš ๏ธ",
147
+ verified: "โœ”๏ธ",
148
+ blocked: "โ›”",
149
+ allowed: "๐ŸŸข",
150
+ connected: "๐Ÿ”—",
151
+ disconnected: "โŒ",
152
+ online: "๐ŸŸข",
153
+ offline: "๐Ÿ”ด",
154
+ latency: "๐Ÿ“ถ",
155
+ proxying: "๐Ÿงญ",
156
+ broadcasting: "๐Ÿ“ฃ",
157
+ thinking: "๐Ÿค”",
158
+ learning: "๐Ÿง ",
159
+ predicting: "๐Ÿ”ฎ",
160
+ scanning: "๐Ÿ”",
161
+ crawling: "๐Ÿ•ท๏ธ",
162
+ responding: "๐Ÿ’ฌ",
163
+ generating: "โœจ",
164
+ debug: "๐Ÿž",
165
+ trace: "๐Ÿงต",
166
+ inspect: "๐Ÿ”Ž",
167
+ test: "๐Ÿงช",
168
+ mock: "๐ŸŽญ",
169
+ sandbox: "๐Ÿ–๏ธ",
170
+ experiment: "โš—๏ธ",
171
+ success: "โœ…",
172
+ processing: "๐Ÿ”„",
173
+ listening: "๐Ÿ“ก",
174
+ prune: "๐Ÿงน",
175
+ connect: "๐Ÿ”Œ",
176
+ info: "โ„น๏ธ",
177
+ warn: "โš ๏ธ"
178
+ };
179
+ const COLS = {
180
+ emoji: 2,
181
+ timestamp: 24,
182
+ function: 28,
183
+ message: 0, // flexible
184
+ file: 16,
185
+ };
186
+
187
+ /* ------------------------------------------------------------------ */
188
+ /* Winston logger (Node only) */
189
+ /* ------------------------------------------------------------------ */
190
+ console.log("ENV CHECK:", {
191
+ LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
192
+ LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
193
+ });
194
+ function getLogConfig() {
195
+ return {
196
+ condensed: process.env.LOG_CONDENSED !== "false",
197
+ expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
198
+ showDetails: process.env.LOG_SHOW_DETAILS !== "false",
199
+ maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
200
+ activityBlocklist: parse$1(process.env.LOG_ACTIVITY_BLOCKLIST),
201
+ logTypeBlocklist: parse$1(process.env.LOG_TYPE_BLOCKLIST),
202
+ sampleRate: Number(process.env.LOG_SAMPLE_RATE ?? 1), // 0โ€“1
203
+ // ๐Ÿ‘‡ NEW
204
+ prettyDetails: process.env.LOG_PRETTY_DETAILS === "true",
205
+ showDetailslist: process.env.LOG_DETAILS_ALLOWLIST
206
+ ? process.env.LOG_DETAILS_ALLOWLIST.split(",").map(s => s.trim())
207
+ : [],
208
+ functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
209
+ ? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
210
+ : [],
211
+ functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
212
+ ? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
213
+ : [],
214
+ };
215
+ }
216
+ function parse$1(v) {
217
+ return v ? v.split(",").map(s => s.trim()) : [];
218
+ }
16
219
 
17
220
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
18
221
 
@@ -3221,14 +3424,14 @@ var fecha = {
3221
3424
  };
3222
3425
 
3223
3426
  var fecha$1 = /*#__PURE__*/Object.freeze({
3224
- __proto__: null,
3225
- assign: assign,
3226
- default: fecha,
3227
- defaultI18n: defaultI18n,
3228
- format: format$1,
3229
- parse: parse,
3230
- setGlobalDateI18n: setGlobalDateI18n,
3231
- setGlobalDateMasks: setGlobalDateMasks
3427
+ __proto__: null,
3428
+ assign: assign,
3429
+ default: fecha,
3430
+ defaultI18n: defaultI18n,
3431
+ format: format$1,
3432
+ parse: parse,
3433
+ setGlobalDateI18n: setGlobalDateI18n,
3434
+ setGlobalDateMasks: setGlobalDateMasks
3232
3435
  });
3233
3436
 
3234
3437
  var require$$0 = /*@__PURE__*/getAugmentedNamespace(fecha$1);
@@ -14462,137 +14665,70 @@ var container = class Container {
14462
14665
  warn.forProperties(exports$1, 'deprecated', ['emitErrs', 'levelLength']);
14463
14666
  } (winston));
14464
14667
 
14465
- /** ---------------------------------------------------------
14466
- * Detect Environment
14467
- * --------------------------------------------------------- */
14468
- const IS_BROWSER = typeof window !== "undefined" &&
14469
- typeof window.document !== "undefined";
14470
- const IS_NODE = typeof process !== "undefined" &&
14471
- process.release?.name === "node";
14472
-
14473
- function getLogConfig() {
14474
- return {
14475
- condensed: process.env.LOG_CONDENSED !== "false",
14476
- expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
14477
- showDetails: process.env.LOG_SHOW_DETAILS !== "false",
14478
- maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
14479
- showDetailslist: process.env.LOG_DETAILS_ALLOWLIST
14480
- ? process.env.LOG_DETAILS_ALLOWLIST.split(",").map(s => s.trim())
14481
- : [],
14482
- functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
14483
- ? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
14484
- : [],
14485
- functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
14486
- ? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
14487
- : [],
14488
- };
14489
- }
14490
-
14668
+ /* ------------------------------------------------------------------ */
14669
+ /* Winston logger (Node only) */
14670
+ /* ------------------------------------------------------------------ */
14491
14671
  console.log("ENV CHECK:", {
14492
14672
  LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
14493
14673
  LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
14494
14674
  });
14495
- let nodeLogger = null;
14496
- if (IS_NODE) {
14497
- nodeLogger = winston.createLogger({
14498
- level: "info",
14499
- format: winston.format.combine(winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.errors({ stack: true }), winston.format.printf(({ timestamp, level, message, stack }) => {
14500
- return `${timestamp} [${level}] ${message}${stack ? "\n" + stack : ""}`;
14501
- })),
14502
- transports: [
14503
- new winston.transports.Console(),
14504
- new winston.transports.File({ filename: "logs/error.log", level: "error" }),
14505
- new winston.transports.File({ filename: "logs/combined.log" }),
14506
- ],
14507
- });
14508
- }
14509
- function shouldCondense(logType) {
14510
- const LOG_CONFIG = getLogConfig();
14511
- if (LOG_CONFIG.expandOnDebug && logType === "debug") {
14512
- return false;
14675
+ function getNodeLogger() {
14676
+ let nodeLogger = null;
14677
+ if (IS_NODE) {
14678
+ nodeLogger = winston.createLogger({
14679
+ level: "info",
14680
+ format: winston.format.combine(winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.errors({ stack: true }), winston.format.printf(({ timestamp, level, message, stack }) => {
14681
+ return `${timestamp} [${level}] ${message}${stack ? "\n" + stack : ""}`;
14682
+ })),
14683
+ transports: [
14684
+ new winston.transports.Console(),
14685
+ new winston.transports.File({ filename: "logs/error.log", level: "error" }),
14686
+ new winston.transports.File({ filename: "logs/combined.log" }),
14687
+ ],
14688
+ });
14513
14689
  }
14514
- return LOG_CONFIG.condensed;
14690
+ return nodeLogger;
14515
14691
  }
14516
- function shouldShowDetails(logType) {
14517
- const cfg = getLogConfig();
14518
- if (cfg.showDetailslist.length > 0) {
14519
- return cfg.showDetailslist.includes(logType);
14692
+ const logger = getNodeLogger();
14693
+ function getFinalLine(line, finalLogType, resolvedLoggerInput) {
14694
+ // ---------------- Browser ----------------
14695
+ if (IS_BROWSER) {
14696
+ console[finalLogType === "error"
14697
+ ? "error"
14698
+ : finalLogType === "warn"
14699
+ ? "warn"
14700
+ : finalLogType === "debug"
14701
+ ? "debug"
14702
+ : "log"](line);
14703
+ return line;
14520
14704
  }
14521
- return cfg.showDetails;
14522
- }
14523
- /** Exported logger */
14524
- const logger = nodeLogger;
14525
- /**
14526
- * Normalizes inputs by treating "unknown" and empty values as null.
14527
- * Returns "unknown" ONLY if all inputs are invalid.
14528
- */
14529
- function resolveValue(...values) {
14530
- let sawInput = false;
14531
- for (const value of values) {
14532
- if (value === undefined || value === null)
14533
- continue;
14534
- sawInput = true;
14535
- if (typeof value === "string") {
14536
- const v = value.trim();
14537
- if (!v || v.toLowerCase() === "unknown")
14538
- continue;
14539
- return value;
14540
- }
14541
- return value;
14705
+ // ---------------- Node ----------------
14706
+ const activeLogger = resolveLogger(resolvedLoggerInput);
14707
+ if (!activeLogger) {
14708
+ console.log(line);
14709
+ return line;
14542
14710
  }
14543
- return sawInput ? "unknown" : "unknown";
14544
- }
14545
- /* ------------------------------------------------------------------ */
14546
- /* Stack inspection */
14547
- /* ------------------------------------------------------------------ */
14548
- function padRight(str, width) {
14549
- return str.length >= width ? str : str + " ".repeat(width - str.length);
14550
- }
14551
- const COLS = {
14552
- timestamp: 24,
14553
- file: 16,
14554
- };
14555
- /* ------------------------------------------------------------------ */
14556
- /* Stack inspection */
14557
- /* ------------------------------------------------------------------ */
14558
- function extractFile(frame) {
14559
- // file:///path/to/file.ts:line:col
14560
- const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
14561
- if (esmMatch)
14562
- return esmMatch[1];
14563
- // (path/to/file.ts:line:col)
14564
- const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
14565
- if (cjsMatch)
14566
- return cjsMatch[1];
14567
- // at path/to/file.ts:line:col
14568
- const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
14569
- if (bareMatch)
14570
- return bareMatch[1];
14571
- return "unknown";
14572
- }
14573
- function getCallerInfo() {
14574
- if (!IS_NODE) {
14575
- return { functionName: "browser", file: "browser" };
14711
+ try {
14712
+ switch (finalLogType) {
14713
+ case "error":
14714
+ activeLogger.error(line);
14715
+ break;
14716
+ case "warn":
14717
+ activeLogger.warn(line);
14718
+ break;
14719
+ case "debug":
14720
+ activeLogger.debug(line);
14721
+ break;
14722
+ default:
14723
+ activeLogger.info(line);
14724
+ }
14576
14725
  }
14577
- const obj = {};
14578
- Error.captureStackTrace(obj, getLogString);
14579
- const stack = obj.stack?.split("\n") ?? [];
14580
- const frame = stack
14581
- .slice(1)
14582
- .find((line) => !line.includes("node:internal") &&
14583
- !line.includes("processTicksAndRejections"));
14584
- if (!frame) {
14585
- return { functionName: "unknown", file: "unknown" };
14726
+ catch {
14727
+ console.log(line);
14586
14728
  }
14587
- const fnMatch = frame.match(/at\s+async\s+([^\s(]+)/) ||
14588
- frame.match(/at\s+([^\s(]+)/);
14589
- return {
14590
- functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
14591
- ? fnMatch[1]
14592
- : "unknown",
14593
- file: extractFile(frame),
14594
- };
14729
+ return line;
14595
14730
  }
14731
+
14596
14732
  /* ------------------------------------------------------------------ */
14597
14733
  /* Safe logger resolver */
14598
14734
  /* ------------------------------------------------------------------ */
@@ -14609,7 +14745,22 @@ function resolveLogger(candidate) {
14609
14745
  }
14610
14746
  return null;
14611
14747
  }
14612
- function serializeDetails(value, condensed, maxLength) {
14748
+ function shouldCondense(logType) {
14749
+ const LOG_CONFIG = getLogConfig();
14750
+ if (LOG_CONFIG.expandOnDebug && logType === "debug") {
14751
+ return false;
14752
+ }
14753
+ return LOG_CONFIG.condensed;
14754
+ }
14755
+ function shouldShowDetails(logType) {
14756
+ const cfg = getLogConfig();
14757
+ if (cfg.showDetailslist.length > 0) {
14758
+ return cfg.showDetailslist.includes(logType);
14759
+ }
14760
+ return cfg.showDetails;
14761
+ }
14762
+ function serializeDetails(value, condensed, maxLength, pretty // ๐Ÿ‘ˆ new
14763
+ ) {
14613
14764
  try {
14614
14765
  const seen = new WeakSet();
14615
14766
  const json = JSON.stringify(value, (key, val) => {
@@ -14623,7 +14774,8 @@ function serializeDetails(value, condensed, maxLength) {
14623
14774
  seen.add(val);
14624
14775
  }
14625
14776
  return val;
14626
- }, condensed ? 0 : 2);
14777
+ }, pretty && !condensed ? 2 : 0 // ๐Ÿ‘ˆ HERE
14778
+ );
14627
14779
  if (condensed && json.length > maxLength) {
14628
14780
  return json.slice(0, maxLength) + "โ€ฆ";
14629
14781
  }
@@ -14633,6 +14785,71 @@ function serializeDetails(value, condensed, maxLength) {
14633
14785
  return "[unserializable details]";
14634
14786
  }
14635
14787
  }
14788
+ function formatLogLine({ emoji, timestamp, functionName, message, details, file, condense, maxDetailsLength, pretty }) {
14789
+ let line = `${padRight(emoji, 3)}` +
14790
+ `[${padRight(timestamp, COLS.timestamp)}] ` +
14791
+ `[${functionName}] ` +
14792
+ `${message}`;
14793
+ if (details !== undefined) {
14794
+ const serialized = serializeDetails(details, condense, maxDetailsLength, pretty);
14795
+ line += ` | ${serialized}`;
14796
+ }
14797
+ line += ` | ${padRight(file, COLS.file)}`;
14798
+ return line;
14799
+ }
14800
+
14801
+ const seen = new Map();
14802
+ function hash(str) {
14803
+ let h = 0;
14804
+ for (let i = 0; i < str.length; i++) {
14805
+ h = (h << 5) - h + str.charCodeAt(i);
14806
+ h |= 0;
14807
+ }
14808
+ return Math.abs(h);
14809
+ }
14810
+ function shouldLog(opts, caller) {
14811
+ const cfg = getLogConfig();
14812
+ const fn = caller.functionName;
14813
+ const type = opts.logType ?? "info";
14814
+ const activity = opts.activity;
14815
+ const message = opts.message;
14816
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14817
+ // 1๏ธโƒฃ Hard allowlist (strongest gate)
14818
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14819
+ if (cfg.functionAllowlist.length > 0) {
14820
+ if (!cfg.functionAllowlist.includes(fn))
14821
+ return false;
14822
+ }
14823
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14824
+ // 2๏ธโƒฃ Hard blocklists
14825
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14826
+ if (cfg.functionBlocklist.includes(fn))
14827
+ return false;
14828
+ if (activity && cfg.activityBlocklist.includes(activity))
14829
+ return false;
14830
+ if (cfg.logTypeBlocklist.includes(type))
14831
+ return false;
14832
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14833
+ // 3๏ธโƒฃ Burst protection (debug spam)
14834
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14835
+ if (type === "debug") {
14836
+ const key = fn + ":" + message;
14837
+ const count = (seen.get(key) ?? 0) + 1;
14838
+ seen.set(key, count);
14839
+ if (count > 5)
14840
+ return false; // drop after 5 identical logs
14841
+ }
14842
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14843
+ // 4๏ธโƒฃ Deterministic sampling
14844
+ // โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
14845
+ if (cfg.sampleRate < 1) {
14846
+ const pct = (hash(fn) % 100) / 100;
14847
+ if (pct > cfg.sampleRate)
14848
+ return false;
14849
+ }
14850
+ return true;
14851
+ }
14852
+
14636
14853
  /* ------------------------------------------------------------------ */
14637
14854
  /* IMPLEMENTATION */
14638
14855
  /* ------------------------------------------------------------------ */
@@ -14656,97 +14873,16 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14656
14873
  }
14657
14874
  let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
14658
14875
  // ---------------- Resolve caller info ----------------
14659
- const { functionName, file } = getCallerInfo();
14660
- // ---------------- Resolve caller info ----------------
14661
- if (!resolvedFunctionName || resolvedFunctionName === "unknown") {
14662
- const { functionName } = getCallerInfo();
14663
- resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
14664
- }
14665
- if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
14666
- const { file } = getCallerInfo();
14667
- resolvedFileLocation = resolveValue(file, resolvedFileLocation);
14876
+ const caller = getCallerInfo(getLogString);
14877
+ if (!shouldLog(opts, caller)) {
14878
+ return ""; // ๐Ÿ”• blocked โ€” nothing emitted
14668
14879
  }
14669
- const emojiMap = {
14670
- emitting: "๐Ÿ“ค",
14671
- ingesting: "๐Ÿ“ฅ",
14672
- streaming: "๐ŸŒŠ",
14673
- forwarding: "โžก๏ธ",
14674
- receiving: "๐Ÿ“ก",
14675
- relaying: "๐Ÿ”",
14676
- syncing: "๐Ÿ”„",
14677
- buffering: "โณ",
14678
- batching: "๐Ÿ“ฆ",
14679
- dispatching: "๐Ÿš€",
14680
- settings: "โš™๏ธ",
14681
- computing: "๐Ÿง ",
14682
- running: "๐Ÿƒ",
14683
- working: "๐Ÿ”ง",
14684
- building: "๐Ÿ—๏ธ",
14685
- compiling: "๐Ÿงฉ",
14686
- crunching: "๐Ÿงฎ",
14687
- optimizing: "๐Ÿ“ˆ",
14688
- queued: "๐Ÿ•’",
14689
- waiting: "โณ",
14690
- active: "โ–ถ๏ธ",
14691
- paused: "โธ๏ธ",
14692
- sleeping: "๐Ÿ’ค",
14693
- resumed: "๐Ÿ”„",
14694
- completed: "โœ…",
14695
- cancelled: "โŒ",
14696
- expired: "โŒ›",
14697
- warning: "โš ๏ธ",
14698
- error: "โŒ",
14699
- critical: "๐Ÿšจ",
14700
- retrying: "๐Ÿ”",
14701
- skipped: "โญ๏ธ",
14702
- fallback: "๐Ÿ›Ÿ",
14703
- degraded: "๐Ÿ“‰",
14704
- saved: "๐Ÿ’พ",
14705
- loading: "๐Ÿ“‚",
14706
- exporting: "๐Ÿ“ค",
14707
- importing: "๐Ÿ“ฅ",
14708
- archived: "๐Ÿ—„๏ธ",
14709
- deleted: "๐Ÿ—‘๏ธ",
14710
- cached: "๐ŸงŠ",
14711
- persisted: "๐Ÿ“Œ",
14712
- locked: "๐Ÿ”’",
14713
- unlocked: "๐Ÿ”“",
14714
- secure: "๐Ÿ›ก๏ธ",
14715
- insecure: "โš ๏ธ",
14716
- verified: "โœ”๏ธ",
14717
- blocked: "โ›”",
14718
- allowed: "๐ŸŸข",
14719
- connected: "๐Ÿ”—",
14720
- disconnected: "โŒ",
14721
- online: "๐ŸŸข",
14722
- offline: "๐Ÿ”ด",
14723
- latency: "๐Ÿ“ถ",
14724
- proxying: "๐Ÿงญ",
14725
- broadcasting: "๐Ÿ“ฃ",
14726
- thinking: "๐Ÿค”",
14727
- learning: "๐Ÿง ",
14728
- predicting: "๐Ÿ”ฎ",
14729
- scanning: "๐Ÿ”",
14730
- crawling: "๐Ÿ•ท๏ธ",
14731
- responding: "๐Ÿ’ฌ",
14732
- generating: "โœจ",
14733
- debug: "๐Ÿž",
14734
- trace: "๐Ÿงต",
14735
- inspect: "๐Ÿ”Ž",
14736
- test: "๐Ÿงช",
14737
- mock: "๐ŸŽญ",
14738
- sandbox: "๐Ÿ–๏ธ",
14739
- experiment: "โš—๏ธ",
14740
- success: "โœ…",
14741
- processing: "๐Ÿ”„",
14742
- listening: "๐Ÿ“ก",
14743
- prune: "๐Ÿงน",
14744
- connect: "๐Ÿ”Œ",
14745
- info: "โ„น๏ธ",
14746
- warn: "โš ๏ธ"
14747
- };
14880
+ // ---------------- Resolve caller info ----------------
14881
+ resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
14882
+ resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
14748
14883
  const finalLogType = resolvedLogType ?? "info";
14749
- const emoji = emojiMap[finalLogType] ?? "โ„น๏ธ";
14884
+ const emoji = activityEmojiMap[opts.activity ?? ""] ??
14885
+ "โ„น๏ธ";
14750
14886
  const timestamp = new Date().toISOString();
14751
14887
  const condense = shouldCondense(finalLogType);
14752
14888
  const showDetails = shouldShowDetails(finalLogType);
@@ -14763,53 +14899,32 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14763
14899
  `${message}`;
14764
14900
  if (showDetails && resolvedDetails !== null && resolvedDetails !== undefined) {
14765
14901
  const LOG_CONFIG = getLogConfig();
14766
- const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
14902
+ const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength, LOG_CONFIG.prettyDetails // ๐Ÿ‘ˆ HERE
14903
+ );
14767
14904
  line += ` | ${serialized}`;
14768
14905
  }
14769
14906
  line += ` | ${fileName}`;
14770
- // ---------------- Browser ----------------
14771
- if (IS_BROWSER) {
14772
- console[finalLogType === "error"
14773
- ? "error"
14774
- : finalLogType === "warn"
14775
- ? "warn"
14776
- : finalLogType === "debug"
14777
- ? "debug"
14778
- : "log"](line);
14779
- return line;
14780
- }
14781
- // ---------------- Node ----------------
14782
- const activeLogger = resolveLogger(resolvedLoggerInput);
14783
- if (!activeLogger) {
14784
- console.log(line);
14785
- return line;
14786
- }
14787
- try {
14788
- switch (finalLogType) {
14789
- case "error":
14790
- activeLogger.error(line);
14791
- break;
14792
- case "warn":
14793
- activeLogger.warn(line);
14794
- break;
14795
- case "debug":
14796
- activeLogger.debug(line);
14797
- break;
14798
- default:
14799
- activeLogger.info(line);
14800
- }
14801
- }
14802
- catch {
14803
- console.log(line);
14804
- }
14805
- return line;
14907
+ return getFinalLine(line, finalLogType, resolvedLoggerInput);
14806
14908
  }
14807
14909
 
14910
+ exports.COLS = COLS;
14808
14911
  exports.IS_BROWSER = IS_BROWSER;
14809
14912
  exports.IS_NODE = IS_NODE;
14913
+ exports.activityEmojiMap = activityEmojiMap;
14914
+ exports.extractFile = extractFile;
14915
+ exports.formatLogLine = formatLogLine;
14916
+ exports.getCallerInfo = getCallerInfo;
14917
+ exports.getFinalLine = getFinalLine;
14810
14918
  exports.getLogConfig = getLogConfig;
14811
14919
  exports.getLogString = getLogString;
14920
+ exports.getNodeLogger = getNodeLogger;
14812
14921
  exports.logger = logger;
14922
+ exports.padLeft = padLeft;
14923
+ exports.padRight = padRight;
14924
+ exports.parseList = parseList;
14925
+ exports.resolveLogger = resolveLogger;
14813
14926
  exports.resolveValue = resolveValue;
14814
14927
  exports.serializeDetails = serializeDetails;
14928
+ exports.shouldCondense = shouldCondense;
14929
+ exports.shouldShowDetails = shouldShowDetails;
14815
14930
  //# sourceMappingURL=index.js.map