@putkoff/abstract-logger 0.0.34 โ†’ 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 +373 -259
  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 +361 -260
  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,138 +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
- function: 28,
14554
- file: 16,
14555
- };
14556
- /* ------------------------------------------------------------------ */
14557
- /* Stack inspection */
14558
- /* ------------------------------------------------------------------ */
14559
- function extractFile(frame) {
14560
- // file:///path/to/file.ts:line:col
14561
- const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
14562
- if (esmMatch)
14563
- return esmMatch[1];
14564
- // (path/to/file.ts:line:col)
14565
- const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
14566
- if (cjsMatch)
14567
- return cjsMatch[1];
14568
- // at path/to/file.ts:line:col
14569
- const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
14570
- if (bareMatch)
14571
- return bareMatch[1];
14572
- return "unknown";
14573
- }
14574
- function getCallerInfo() {
14575
- if (!IS_NODE) {
14576
- 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
+ }
14577
14725
  }
14578
- const obj = {};
14579
- Error.captureStackTrace(obj, getLogString);
14580
- const stack = obj.stack?.split("\n") ?? [];
14581
- const frame = stack
14582
- .slice(1)
14583
- .find((line) => !line.includes("node:internal") &&
14584
- !line.includes("processTicksAndRejections"));
14585
- if (!frame) {
14586
- return { functionName: "unknown", file: "unknown" };
14726
+ catch {
14727
+ console.log(line);
14587
14728
  }
14588
- const fnMatch = frame.match(/at\s+async\s+([^\s(]+)/) ||
14589
- frame.match(/at\s+([^\s(]+)/);
14590
- return {
14591
- functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
14592
- ? fnMatch[1]
14593
- : "unknown",
14594
- file: extractFile(frame),
14595
- };
14729
+ return line;
14596
14730
  }
14731
+
14597
14732
  /* ------------------------------------------------------------------ */
14598
14733
  /* Safe logger resolver */
14599
14734
  /* ------------------------------------------------------------------ */
@@ -14610,7 +14745,22 @@ function resolveLogger(candidate) {
14610
14745
  }
14611
14746
  return null;
14612
14747
  }
14613
- 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
+ ) {
14614
14764
  try {
14615
14765
  const seen = new WeakSet();
14616
14766
  const json = JSON.stringify(value, (key, val) => {
@@ -14624,7 +14774,8 @@ function serializeDetails(value, condensed, maxLength) {
14624
14774
  seen.add(val);
14625
14775
  }
14626
14776
  return val;
14627
- }, condensed ? 0 : 2);
14777
+ }, pretty && !condensed ? 2 : 0 // ๐Ÿ‘ˆ HERE
14778
+ );
14628
14779
  if (condensed && json.length > maxLength) {
14629
14780
  return json.slice(0, maxLength) + "โ€ฆ";
14630
14781
  }
@@ -14634,6 +14785,71 @@ function serializeDetails(value, condensed, maxLength) {
14634
14785
  return "[unserializable details]";
14635
14786
  }
14636
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
+
14637
14853
  /* ------------------------------------------------------------------ */
14638
14854
  /* IMPLEMENTATION */
14639
14855
  /* ------------------------------------------------------------------ */
@@ -14657,97 +14873,16 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14657
14873
  }
14658
14874
  let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
14659
14875
  // ---------------- Resolve caller info ----------------
14660
- const { functionName, file } = getCallerInfo();
14661
- // ---------------- Resolve caller info ----------------
14662
- if (!resolvedFunctionName || resolvedFunctionName === "unknown") {
14663
- const { functionName } = getCallerInfo();
14664
- resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
14665
- }
14666
- if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
14667
- const { file } = getCallerInfo();
14668
- resolvedFileLocation = resolveValue(file, resolvedFileLocation);
14876
+ const caller = getCallerInfo(getLogString);
14877
+ if (!shouldLog(opts, caller)) {
14878
+ return ""; // ๐Ÿ”• blocked โ€” nothing emitted
14669
14879
  }
14670
- const emojiMap = {
14671
- emitting: "๐Ÿ“ค",
14672
- ingesting: "๐Ÿ“ฅ",
14673
- streaming: "๐ŸŒŠ",
14674
- forwarding: "โžก๏ธ",
14675
- receiving: "๐Ÿ“ก",
14676
- relaying: "๐Ÿ”",
14677
- syncing: "๐Ÿ”„",
14678
- buffering: "โณ",
14679
- batching: "๐Ÿ“ฆ",
14680
- dispatching: "๐Ÿš€",
14681
- settings: "โš™๏ธ",
14682
- computing: "๐Ÿง ",
14683
- running: "๐Ÿƒ",
14684
- working: "๐Ÿ”ง",
14685
- building: "๐Ÿ—๏ธ",
14686
- compiling: "๐Ÿงฉ",
14687
- crunching: "๐Ÿงฎ",
14688
- optimizing: "๐Ÿ“ˆ",
14689
- queued: "๐Ÿ•’",
14690
- waiting: "โณ",
14691
- active: "โ–ถ๏ธ",
14692
- paused: "โธ๏ธ",
14693
- sleeping: "๐Ÿ’ค",
14694
- resumed: "๐Ÿ”„",
14695
- completed: "โœ…",
14696
- cancelled: "โŒ",
14697
- expired: "โŒ›",
14698
- warning: "โš ๏ธ",
14699
- error: "โŒ",
14700
- critical: "๐Ÿšจ",
14701
- retrying: "๐Ÿ”",
14702
- skipped: "โญ๏ธ",
14703
- fallback: "๐Ÿ›Ÿ",
14704
- degraded: "๐Ÿ“‰",
14705
- saved: "๐Ÿ’พ",
14706
- loading: "๐Ÿ“‚",
14707
- exporting: "๐Ÿ“ค",
14708
- importing: "๐Ÿ“ฅ",
14709
- archived: "๐Ÿ—„๏ธ",
14710
- deleted: "๐Ÿ—‘๏ธ",
14711
- cached: "๐ŸงŠ",
14712
- persisted: "๐Ÿ“Œ",
14713
- locked: "๐Ÿ”’",
14714
- unlocked: "๐Ÿ”“",
14715
- secure: "๐Ÿ›ก๏ธ",
14716
- insecure: "โš ๏ธ",
14717
- verified: "โœ”๏ธ",
14718
- blocked: "โ›”",
14719
- allowed: "๐ŸŸข",
14720
- connected: "๐Ÿ”—",
14721
- disconnected: "โŒ",
14722
- online: "๐ŸŸข",
14723
- offline: "๐Ÿ”ด",
14724
- latency: "๐Ÿ“ถ",
14725
- proxying: "๐Ÿงญ",
14726
- broadcasting: "๐Ÿ“ฃ",
14727
- thinking: "๐Ÿค”",
14728
- learning: "๐Ÿง ",
14729
- predicting: "๐Ÿ”ฎ",
14730
- scanning: "๐Ÿ”",
14731
- crawling: "๐Ÿ•ท๏ธ",
14732
- responding: "๐Ÿ’ฌ",
14733
- generating: "โœจ",
14734
- debug: "๐Ÿž",
14735
- trace: "๐Ÿงต",
14736
- inspect: "๐Ÿ”Ž",
14737
- test: "๐Ÿงช",
14738
- mock: "๐ŸŽญ",
14739
- sandbox: "๐Ÿ–๏ธ",
14740
- experiment: "โš—๏ธ",
14741
- success: "โœ…",
14742
- processing: "๐Ÿ”„",
14743
- listening: "๐Ÿ“ก",
14744
- prune: "๐Ÿงน",
14745
- connect: "๐Ÿ”Œ",
14746
- info: "โ„น๏ธ",
14747
- warn: "โš ๏ธ"
14748
- };
14880
+ // ---------------- Resolve caller info ----------------
14881
+ resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
14882
+ resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
14749
14883
  const finalLogType = resolvedLogType ?? "info";
14750
- const emoji = emojiMap[finalLogType] ?? "โ„น๏ธ";
14884
+ const emoji = activityEmojiMap[opts.activity ?? ""] ??
14885
+ "โ„น๏ธ";
14751
14886
  const timestamp = new Date().toISOString();
14752
14887
  const condense = shouldCondense(finalLogType);
14753
14888
  const showDetails = shouldShowDetails(finalLogType);
@@ -14756,7 +14891,7 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14756
14891
  }
14757
14892
  const emojiCol = padRight(emoji, 3);
14758
14893
  const ts = padRight(timestamp, COLS.timestamp);
14759
- const fn = padRight(resolvedFunctionName.trim(), COLS.function);
14894
+ const fn = resolvedFunctionName;
14760
14895
  const fileName = padRight(resolvedFileLocation.trim(), COLS.file);
14761
14896
  let line = `${emojiCol}` +
14762
14897
  `[${ts}] ` +
@@ -14764,53 +14899,32 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14764
14899
  `${message}`;
14765
14900
  if (showDetails && resolvedDetails !== null && resolvedDetails !== undefined) {
14766
14901
  const LOG_CONFIG = getLogConfig();
14767
- const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
14902
+ const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength, LOG_CONFIG.prettyDetails // ๐Ÿ‘ˆ HERE
14903
+ );
14768
14904
  line += ` | ${serialized}`;
14769
14905
  }
14770
14906
  line += ` | ${fileName}`;
14771
- // ---------------- Browser ----------------
14772
- if (IS_BROWSER) {
14773
- console[finalLogType === "error"
14774
- ? "error"
14775
- : finalLogType === "warn"
14776
- ? "warn"
14777
- : finalLogType === "debug"
14778
- ? "debug"
14779
- : "log"](line);
14780
- return line;
14781
- }
14782
- // ---------------- Node ----------------
14783
- const activeLogger = resolveLogger(resolvedLoggerInput);
14784
- if (!activeLogger) {
14785
- console.log(line);
14786
- return line;
14787
- }
14788
- try {
14789
- switch (finalLogType) {
14790
- case "error":
14791
- activeLogger.error(line);
14792
- break;
14793
- case "warn":
14794
- activeLogger.warn(line);
14795
- break;
14796
- case "debug":
14797
- activeLogger.debug(line);
14798
- break;
14799
- default:
14800
- activeLogger.info(line);
14801
- }
14802
- }
14803
- catch {
14804
- console.log(line);
14805
- }
14806
- return line;
14907
+ return getFinalLine(line, finalLogType, resolvedLoggerInput);
14807
14908
  }
14808
14909
 
14910
+ exports.COLS = COLS;
14809
14911
  exports.IS_BROWSER = IS_BROWSER;
14810
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;
14811
14918
  exports.getLogConfig = getLogConfig;
14812
14919
  exports.getLogString = getLogString;
14920
+ exports.getNodeLogger = getNodeLogger;
14813
14921
  exports.logger = logger;
14922
+ exports.padLeft = padLeft;
14923
+ exports.padRight = padRight;
14924
+ exports.parseList = parseList;
14925
+ exports.resolveLogger = resolveLogger;
14814
14926
  exports.resolveValue = resolveValue;
14815
14927
  exports.serializeDetails = serializeDetails;
14928
+ exports.shouldCondense = shouldCondense;
14929
+ exports.shouldShowDetails = shouldShowDetails;
14816
14930
  //# sourceMappingURL=index.js.map