@putkoff/abstract-logger 0.0.16 → 0.0.17
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 +56 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/logger/logger.d.ts +5 -0
- package/dist/esm/index.js +56 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/logger/logger.d.ts +5 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/logger/logger.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -14488,25 +14488,68 @@ if (IS_NODE) {
|
|
|
14488
14488
|
}
|
|
14489
14489
|
/** Exported logger */
|
|
14490
14490
|
const logger = nodeLogger;
|
|
14491
|
+
/**
|
|
14492
|
+
* Normalizes inputs by treating "unknown" and empty values as null.
|
|
14493
|
+
* Returns "unknown" ONLY if all inputs are invalid.
|
|
14494
|
+
*/
|
|
14495
|
+
function resolveValue(...values) {
|
|
14496
|
+
let sawInput = false;
|
|
14497
|
+
for (const value of values) {
|
|
14498
|
+
if (value === undefined || value === null)
|
|
14499
|
+
continue;
|
|
14500
|
+
sawInput = true;
|
|
14501
|
+
if (typeof value === "string") {
|
|
14502
|
+
const v = value.trim();
|
|
14503
|
+
if (!v || v.toLowerCase() === "unknown")
|
|
14504
|
+
continue;
|
|
14505
|
+
return value;
|
|
14506
|
+
}
|
|
14507
|
+
return value;
|
|
14508
|
+
}
|
|
14509
|
+
return sawInput ? "unknown" : "unknown";
|
|
14510
|
+
}
|
|
14491
14511
|
/* ------------------------------------------------------------------ */
|
|
14492
14512
|
/* Stack inspection */
|
|
14493
14513
|
/* ------------------------------------------------------------------ */
|
|
14514
|
+
/* ------------------------------------------------------------------ */
|
|
14515
|
+
/* Stack inspection */
|
|
14516
|
+
/* ------------------------------------------------------------------ */
|
|
14517
|
+
function extractFile(frame) {
|
|
14518
|
+
// file:///path/to/file.ts:line:col
|
|
14519
|
+
const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
|
|
14520
|
+
if (esmMatch)
|
|
14521
|
+
return esmMatch[1];
|
|
14522
|
+
// (path/to/file.ts:line:col)
|
|
14523
|
+
const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
|
|
14524
|
+
if (cjsMatch)
|
|
14525
|
+
return cjsMatch[1];
|
|
14526
|
+
// at path/to/file.ts:line:col
|
|
14527
|
+
const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
|
|
14528
|
+
if (bareMatch)
|
|
14529
|
+
return bareMatch[1];
|
|
14530
|
+
return "unknown";
|
|
14531
|
+
}
|
|
14494
14532
|
function getCallerInfo() {
|
|
14495
14533
|
if (!IS_NODE) {
|
|
14496
14534
|
return { functionName: "browser", file: "browser" };
|
|
14497
14535
|
}
|
|
14498
14536
|
const obj = {};
|
|
14499
|
-
Error.captureStackTrace(obj,
|
|
14537
|
+
Error.captureStackTrace(obj, getLogString);
|
|
14500
14538
|
const stack = obj.stack?.split("\n") ?? [];
|
|
14501
|
-
const frame = stack
|
|
14502
|
-
|
|
14503
|
-
|
|
14539
|
+
const frame = stack
|
|
14540
|
+
.slice(1)
|
|
14541
|
+
.find((line) => !line.includes("node:internal") &&
|
|
14542
|
+
!line.includes("processTicksAndRejections"));
|
|
14543
|
+
if (!frame) {
|
|
14504
14544
|
return { functionName: "unknown", file: "unknown" };
|
|
14505
|
-
|
|
14506
|
-
const
|
|
14545
|
+
}
|
|
14546
|
+
const fnMatch = frame.match(/at\s+async\s+([^\s(]+)/) ||
|
|
14547
|
+
frame.match(/at\s+([^\s(]+)/);
|
|
14507
14548
|
return {
|
|
14508
|
-
functionName: fnMatch?.[1]
|
|
14509
|
-
|
|
14549
|
+
functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
|
|
14550
|
+
? fnMatch[1]
|
|
14551
|
+
: "unknown",
|
|
14552
|
+
file: extractFile(frame),
|
|
14510
14553
|
};
|
|
14511
14554
|
}
|
|
14512
14555
|
/* ------------------------------------------------------------------ */
|
|
@@ -14530,8 +14573,8 @@ function resolveLogger(candidate) {
|
|
|
14530
14573
|
/* ------------------------------------------------------------------ */
|
|
14531
14574
|
function getLogString(message, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
|
|
14532
14575
|
let { functionName, file } = getCallerInfo();
|
|
14533
|
-
function_name = functionName
|
|
14534
|
-
file_location = file
|
|
14576
|
+
function_name = resolveValue(functionName !== "unknown" ? functionName : null, function_name);
|
|
14577
|
+
file_location = resolveValue(file !== "unknown" ? file : null, file_location);
|
|
14535
14578
|
const emojiMap = {
|
|
14536
14579
|
info: "ℹ️",
|
|
14537
14580
|
warn: "⚠️",
|
|
@@ -14541,7 +14584,7 @@ function getLogString(message, logType = null, details = null, function_name = n
|
|
|
14541
14584
|
logType = logType || "info";
|
|
14542
14585
|
const emoji = emojiMap[logType] ?? "ℹ️";
|
|
14543
14586
|
const timestamp = new Date().toISOString();
|
|
14544
|
-
let line = `${emoji} [${timestamp}] [${function_name}] ${message}
|
|
14587
|
+
let line = `${emoji} [${timestamp}] [${function_name}] ${message}`;
|
|
14545
14588
|
if (details !== null && details !== undefined) {
|
|
14546
14589
|
try {
|
|
14547
14590
|
const seen = new WeakSet();
|
|
@@ -14563,6 +14606,7 @@ function getLogString(message, logType = null, details = null, function_name = n
|
|
|
14563
14606
|
line += ` | [unserializable details]`;
|
|
14564
14607
|
}
|
|
14565
14608
|
}
|
|
14609
|
+
line += ` | ${file_location}`;
|
|
14566
14610
|
/* ---------------- Browser ---------------- */
|
|
14567
14611
|
if (IS_BROWSER) {
|
|
14568
14612
|
console[logType === "error" ? "error" :
|
|
@@ -14599,4 +14643,5 @@ function getLogString(message, logType = null, details = null, function_name = n
|
|
|
14599
14643
|
|
|
14600
14644
|
exports.getLogString = getLogString;
|
|
14601
14645
|
exports.logger = logger;
|
|
14646
|
+
exports.resolveValue = resolveValue;
|
|
14602
14647
|
//# sourceMappingURL=index.js.map
|