@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 +41 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/logger/logger.d.ts +10 -2
- package/dist/esm/index.js +41 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/logger/logger.d.ts +10 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/logger/logger.d.ts +10 -2
- package/package.json +1 -1
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(
|
|
14575
|
-
|
|
14576
|
-
|
|
14577
|
-
|
|
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
|
-
|
|
14585
|
-
const emoji = emojiMap[
|
|
14603
|
+
const finalLogType = resolvedLogType ?? "info";
|
|
14604
|
+
const emoji = emojiMap[finalLogType] ?? "ℹ️";
|
|
14586
14605
|
const timestamp = new Date().toISOString();
|
|
14587
|
-
let line = `${emoji} [${timestamp}] [${
|
|
14588
|
-
|
|
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(
|
|
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 += ` | ${
|
|
14610
|
-
|
|
14629
|
+
line += ` | ${resolvedFileLocation}`;
|
|
14630
|
+
// ---------------- Browser ----------------
|
|
14611
14631
|
if (IS_BROWSER) {
|
|
14612
|
-
console[
|
|
14613
|
-
|
|
14614
|
-
|
|
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
|
-
|
|
14618
|
-
const activeLogger = resolveLogger(
|
|
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 (
|
|
14648
|
+
switch (finalLogType) {
|
|
14625
14649
|
case "error":
|
|
14626
14650
|
activeLogger.error(line);
|
|
14627
14651
|
break;
|