@putkoff/abstract-logger 0.0.35 → 0.0.38

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 +389 -269
  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 +377 -270
  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,160 +14873,63 @@ 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] ?? "ℹ️";
14750
- const timestamp = new Date().toISOString();
14884
+ const emoji = activityEmojiMap[opts.activity ?? ""] ??
14885
+ "ℹ️";
14886
+ const LOG_CONFIG = getLogConfig();
14751
14887
  const condense = shouldCondense(finalLogType);
14752
14888
  const showDetails = shouldShowDetails(finalLogType);
14889
+ // 👇 ADD THIS
14890
+ const pretty = LOG_CONFIG.prettyDetails &&
14891
+ !condense;
14892
+ const timestamp = new Date().toISOString();
14753
14893
  if (condense) {
14754
14894
  resolvedFileLocation = resolvedFileLocation.split("/").pop();
14755
14895
  }
14756
- const emojiCol = padRight(emoji, 3);
14757
- const ts = padRight(timestamp, COLS.timestamp);
14758
- const fn = resolvedFunctionName;
14759
- const fileName = padRight(resolvedFileLocation.trim(), COLS.file);
14760
- let line = `${emojiCol}` +
14761
- `[${ts}] ` +
14762
- `[${fn}] ` +
14763
- `${message}`;
14896
+ padRight(emoji, 3);
14897
+ padRight(timestamp, COLS.timestamp);
14898
+ padRight(resolvedFileLocation.trim(), COLS.file);
14764
14899
  if (showDetails && resolvedDetails !== null && resolvedDetails !== undefined) {
14765
- const LOG_CONFIG = getLogConfig();
14766
- const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
14767
- line += ` | ${serialized}`;
14900
+ serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength, pretty);
14768
14901
  }
14769
- 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;
14902
+ return getFinalLine(formatLogLine({
14903
+ emoji,
14904
+ timestamp,
14905
+ functionName: resolvedFunctionName,
14906
+ message,
14907
+ details: showDetails ? resolvedDetails : undefined,
14908
+ file: resolvedFileLocation,
14909
+ condense,
14910
+ maxDetailsLength: LOG_CONFIG.maxDetailsLength,
14911
+ pretty, // 👈 THIS IS THE MISSING WIRE
14912
+ }), finalLogType, resolvedLoggerInput);
14806
14913
  }
14807
14914
 
14915
+ exports.COLS = COLS;
14808
14916
  exports.IS_BROWSER = IS_BROWSER;
14809
14917
  exports.IS_NODE = IS_NODE;
14918
+ exports.activityEmojiMap = activityEmojiMap;
14919
+ exports.extractFile = extractFile;
14920
+ exports.formatLogLine = formatLogLine;
14921
+ exports.getCallerInfo = getCallerInfo;
14922
+ exports.getFinalLine = getFinalLine;
14810
14923
  exports.getLogConfig = getLogConfig;
14811
14924
  exports.getLogString = getLogString;
14925
+ exports.getNodeLogger = getNodeLogger;
14812
14926
  exports.logger = logger;
14927
+ exports.padLeft = padLeft;
14928
+ exports.padRight = padRight;
14929
+ exports.parseList = parseList;
14930
+ exports.resolveLogger = resolveLogger;
14813
14931
  exports.resolveValue = resolveValue;
14814
14932
  exports.serializeDetails = serializeDetails;
14933
+ exports.shouldCondense = shouldCondense;
14934
+ exports.shouldShowDetails = shouldShowDetails;
14815
14935
  //# sourceMappingURL=index.js.map