@putkoff/abstract-logger 0.0.19 → 0.0.21

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/cjs/index.js CHANGED
@@ -14469,6 +14469,23 @@ const IS_BROWSER = typeof window !== "undefined" &&
14469
14469
  const IS_NODE = typeof process !== "undefined" &&
14470
14470
  process.release?.name === "node";
14471
14471
 
14472
+ const LOG_CONFIG = {
14473
+ condensed: process.env.LOG_CONDENSED !== "false",
14474
+ expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
14475
+ maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
14476
+ /**
14477
+ * Function-level filtering
14478
+ * - empty allowlist = allow all
14479
+ * - blocklist always wins
14480
+ */
14481
+ functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
14482
+ ? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
14483
+ : [],
14484
+ functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
14485
+ ? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
14486
+ : [],
14487
+ };
14488
+
14472
14489
  /* ------------------------------------------------------------------ */
14473
14490
  /* Winston logger (Node only) */
14474
14491
  /* ------------------------------------------------------------------ */
@@ -14486,6 +14503,12 @@ if (IS_NODE) {
14486
14503
  ],
14487
14504
  });
14488
14505
  }
14506
+ function shouldCondense(logType) {
14507
+ if (LOG_CONFIG.expandOnDebug && logType === "debug") {
14508
+ return false;
14509
+ }
14510
+ return LOG_CONFIG.condensed;
14511
+ }
14489
14512
  /** Exported logger */
14490
14513
  const logger = nodeLogger;
14491
14514
  /**
@@ -14568,6 +14591,30 @@ function resolveLogger(candidate) {
14568
14591
  }
14569
14592
  return null;
14570
14593
  }
14594
+ function serializeDetails(value, condensed, maxLength) {
14595
+ try {
14596
+ const seen = new WeakSet();
14597
+ const json = JSON.stringify(value, (key, val) => {
14598
+ if (typeof val === "function")
14599
+ return undefined;
14600
+ if (typeof val === "bigint")
14601
+ return val.toString();
14602
+ if (typeof val === "object" && val !== null) {
14603
+ if (seen.has(val))
14604
+ return "[Circular]";
14605
+ seen.add(val);
14606
+ }
14607
+ return val;
14608
+ }, condensed ? 0 : 2);
14609
+ if (condensed && json.length > maxLength) {
14610
+ return json.slice(0, maxLength) + "…";
14611
+ }
14612
+ return json;
14613
+ }
14614
+ catch {
14615
+ return "[unserializable details]";
14616
+ }
14617
+ }
14571
14618
  /* ------------------------------------------------------------------ */
14572
14619
  /* IMPLEMENTATION */
14573
14620
  /* ------------------------------------------------------------------ */
@@ -14592,8 +14639,15 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14592
14639
  let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
14593
14640
  // ---------------- Resolve caller info ----------------
14594
14641
  const { functionName, file } = getCallerInfo();
14595
- resolvedFunctionName = resolveValue(functionName !== "unknown" ? functionName : null, resolvedFunctionName);
14596
- resolvedFileLocation = resolveValue(file !== "unknown" ? file : null, resolvedFileLocation);
14642
+ // ---------------- Resolve caller info ----------------
14643
+ if (!resolvedFunctionName || resolvedFunctionName === "unknown") {
14644
+ const { functionName } = getCallerInfo();
14645
+ resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
14646
+ }
14647
+ if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
14648
+ const { file } = getCallerInfo();
14649
+ resolvedFileLocation = resolveValue(file, resolvedFileLocation);
14650
+ }
14597
14651
  const emojiMap = {
14598
14652
  info: "ℹ️",
14599
14653
  warn: "⚠️",
@@ -14603,28 +14657,15 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14603
14657
  const finalLogType = resolvedLogType ?? "info";
14604
14658
  const emoji = emojiMap[finalLogType] ?? "ℹ️";
14605
14659
  const timestamp = new Date().toISOString();
14660
+ const condense = shouldCondense(finalLogType);
14661
+ if (condense) {
14662
+ resolvedFileLocation = resolvedFileLocation.split("/").pop();
14663
+ }
14606
14664
  let line = `${emoji} [${timestamp}] [${resolvedFunctionName}] ${message}`;
14607
14665
  // ---------------- Details serialization ----------------
14608
14666
  if (resolvedDetails !== null && resolvedDetails !== undefined) {
14609
- try {
14610
- const seen = new WeakSet();
14611
- const safe = JSON.stringify(resolvedDetails, (key, value) => {
14612
- if (typeof value === "function")
14613
- return undefined;
14614
- if (typeof value === "bigint")
14615
- return value.toString();
14616
- if (typeof value === "object" && value !== null) {
14617
- if (seen.has(value))
14618
- return "[Circular]";
14619
- seen.add(value);
14620
- }
14621
- return value;
14622
- }, 2);
14623
- line += ` | ${safe}`;
14624
- }
14625
- catch {
14626
- line += ` | [unserializable details]`;
14627
- }
14667
+ const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
14668
+ line += ` | ${serialized}`;
14628
14669
  }
14629
14670
  line += ` | ${resolvedFileLocation}`;
14630
14671
  // ---------------- Browser ----------------
@@ -14665,7 +14706,11 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14665
14706
  return line;
14666
14707
  }
14667
14708
 
14709
+ exports.IS_BROWSER = IS_BROWSER;
14710
+ exports.IS_NODE = IS_NODE;
14711
+ exports.LOG_CONFIG = LOG_CONFIG;
14668
14712
  exports.getLogString = getLogString;
14669
14713
  exports.logger = logger;
14670
14714
  exports.resolveValue = resolveValue;
14715
+ exports.serializeDetails = serializeDetails;
14671
14716
  //# sourceMappingURL=index.js.map