@putkoff/abstract-logger 0.0.17 → 0.0.18

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
@@ -14571,24 +14571,44 @@ function resolveLogger(candidate) {
14571
14571
  /* ------------------------------------------------------------------ */
14572
14572
  /* UNIVERSAL getLogString (cannot crash) */
14573
14573
  /* ------------------------------------------------------------------ */
14574
- function getLogString(message, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
14575
- let { functionName, file } = getCallerInfo();
14576
- function_name = resolveValue(functionName !== "unknown" ? functionName : null, function_name);
14577
- file_location = resolveValue(file !== "unknown" ? file : null, file_location);
14574
+ function getLogString(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
14575
+ // ---------------- Normalize inputs ----------------
14576
+ let opts;
14577
+ if (typeof messageOrOptions === "object" && messageOrOptions !== null) {
14578
+ // Dict-style
14579
+ opts = messageOrOptions;
14580
+ }
14581
+ else {
14582
+ // Positional-style
14583
+ opts = {
14584
+ message: messageOrOptions,
14585
+ logType,
14586
+ details,
14587
+ function_name,
14588
+ file_location,
14589
+ consumerLogger,
14590
+ };
14591
+ }
14592
+ let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
14593
+ // ---------------- Resolve caller info ----------------
14594
+ const { functionName, file } = getCallerInfo();
14595
+ resolvedFunctionName = resolveValue(functionName !== "unknown" ? functionName : null, resolvedFunctionName);
14596
+ resolvedFileLocation = resolveValue(file !== "unknown" ? file : null, resolvedFileLocation);
14578
14597
  const emojiMap = {
14579
14598
  info: "ℹ️",
14580
14599
  warn: "⚠️",
14581
14600
  error: "❌",
14582
14601
  debug: "🔍",
14583
14602
  };
14584
- logType = logType || "info";
14585
- const emoji = emojiMap[logType] ?? "ℹ️";
14603
+ const finalLogType = resolvedLogType ?? "info";
14604
+ const emoji = emojiMap[finalLogType] ?? "ℹ️";
14586
14605
  const timestamp = new Date().toISOString();
14587
- let line = `${emoji} [${timestamp}] [${function_name}] ${message}`;
14588
- if (details !== null && details !== undefined) {
14606
+ let line = `${emoji} [${timestamp}] [${resolvedFunctionName}] ${message}`;
14607
+ // ---------------- Details serialization ----------------
14608
+ if (resolvedDetails !== null && resolvedDetails !== undefined) {
14589
14609
  try {
14590
14610
  const seen = new WeakSet();
14591
- const safe = JSON.stringify(details, (key, value) => {
14611
+ const safe = JSON.stringify(resolvedDetails, (key, value) => {
14592
14612
  if (typeof value === "function")
14593
14613
  return undefined;
14594
14614
  if (typeof value === "bigint")
@@ -14606,22 +14626,26 @@ function getLogString(message, logType = null, details = null, function_name = n
14606
14626
  line += ` | [unserializable details]`;
14607
14627
  }
14608
14628
  }
14609
- line += ` | ${file_location}`;
14610
- /* ---------------- Browser ---------------- */
14629
+ line += ` | ${resolvedFileLocation}`;
14630
+ // ---------------- Browser ----------------
14611
14631
  if (IS_BROWSER) {
14612
- console[logType === "error" ? "error" :
14613
- logType === "warn" ? "warn" :
14614
- logType === "debug" ? "debug" : "log"](line);
14632
+ console[finalLogType === "error"
14633
+ ? "error"
14634
+ : finalLogType === "warn"
14635
+ ? "warn"
14636
+ : finalLogType === "debug"
14637
+ ? "debug"
14638
+ : "log"](line);
14615
14639
  return line;
14616
14640
  }
14617
- /* ---------------- Node ---------------- */
14618
- const activeLogger = resolveLogger(consumerLogger);
14641
+ // ---------------- Node ----------------
14642
+ const activeLogger = resolveLogger(resolvedLoggerInput);
14619
14643
  if (!activeLogger) {
14620
14644
  console.log(line);
14621
14645
  return line;
14622
14646
  }
14623
14647
  try {
14624
- switch (logType) {
14648
+ switch (finalLogType) {
14625
14649
  case "error":
14626
14650
  activeLogger.error(line);
14627
14651
  break;