@putkoff/abstract-logger 0.0.15 → 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 +59 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/logger/logger.d.ts +8 -1
- package/dist/esm/index.js +59 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/logger/logger.d.ts +8 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/logger/logger.d.ts +8 -1
- 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
|
/* ------------------------------------------------------------------ */
|
|
@@ -14528,17 +14571,20 @@ function resolveLogger(candidate) {
|
|
|
14528
14571
|
/* ------------------------------------------------------------------ */
|
|
14529
14572
|
/* UNIVERSAL getLogString (cannot crash) */
|
|
14530
14573
|
/* ------------------------------------------------------------------ */
|
|
14531
|
-
function getLogString(message, details = null,
|
|
14532
|
-
|
|
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);
|
|
14533
14578
|
const emojiMap = {
|
|
14534
14579
|
info: "ℹ️",
|
|
14535
14580
|
warn: "⚠️",
|
|
14536
14581
|
error: "❌",
|
|
14537
14582
|
debug: "🔍",
|
|
14538
14583
|
};
|
|
14584
|
+
logType = logType || "info";
|
|
14539
14585
|
const emoji = emojiMap[logType] ?? "ℹ️";
|
|
14540
14586
|
const timestamp = new Date().toISOString();
|
|
14541
|
-
let line = `${emoji} [${timestamp}] [${
|
|
14587
|
+
let line = `${emoji} [${timestamp}] [${function_name}] ${message}`;
|
|
14542
14588
|
if (details !== null && details !== undefined) {
|
|
14543
14589
|
try {
|
|
14544
14590
|
const seen = new WeakSet();
|
|
@@ -14560,6 +14606,7 @@ function getLogString(message, details = null, logType = "info", consumerLogger
|
|
|
14560
14606
|
line += ` | [unserializable details]`;
|
|
14561
14607
|
}
|
|
14562
14608
|
}
|
|
14609
|
+
line += ` | ${file_location}`;
|
|
14563
14610
|
/* ---------------- Browser ---------------- */
|
|
14564
14611
|
if (IS_BROWSER) {
|
|
14565
14612
|
console[logType === "error" ? "error" :
|
|
@@ -14596,4 +14643,5 @@ function getLogString(message, details = null, logType = "info", consumerLogger
|
|
|
14596
14643
|
|
|
14597
14644
|
exports.getLogString = getLogString;
|
|
14598
14645
|
exports.logger = logger;
|
|
14646
|
+
exports.resolveValue = resolveValue;
|
|
14599
14647
|
//# sourceMappingURL=index.js.map
|