@putkoff/abstract-logger 0.0.18 → 0.0.20
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 +47 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/config.d.ts +5 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/logger/logger.d.ts +2 -1
- package/dist/esm/index.js +44 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/config.d.ts +5 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/logger/logger.d.ts +2 -1
- package/dist/types/config.d.ts +5 -0
- package/dist/types/index.d.ts +15 -2
- package/dist/types/logger/logger.d.ts +2 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -14469,6 +14469,12 @@ 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
|
+
|
|
14472
14478
|
/* ------------------------------------------------------------------ */
|
|
14473
14479
|
/* Winston logger (Node only) */
|
|
14474
14480
|
/* ------------------------------------------------------------------ */
|
|
@@ -14486,6 +14492,12 @@ if (IS_NODE) {
|
|
|
14486
14492
|
],
|
|
14487
14493
|
});
|
|
14488
14494
|
}
|
|
14495
|
+
function shouldCondense(logType) {
|
|
14496
|
+
if (LOG_CONFIG.expandOnDebug && logType === "debug") {
|
|
14497
|
+
return false;
|
|
14498
|
+
}
|
|
14499
|
+
return LOG_CONFIG.condensed;
|
|
14500
|
+
}
|
|
14489
14501
|
/** Exported logger */
|
|
14490
14502
|
const logger = nodeLogger;
|
|
14491
14503
|
/**
|
|
@@ -14568,8 +14580,32 @@ function resolveLogger(candidate) {
|
|
|
14568
14580
|
}
|
|
14569
14581
|
return null;
|
|
14570
14582
|
}
|
|
14583
|
+
function serializeDetails(value, condensed, maxLength) {
|
|
14584
|
+
try {
|
|
14585
|
+
const seen = new WeakSet();
|
|
14586
|
+
const json = JSON.stringify(value, (key, val) => {
|
|
14587
|
+
if (typeof val === "function")
|
|
14588
|
+
return undefined;
|
|
14589
|
+
if (typeof val === "bigint")
|
|
14590
|
+
return val.toString();
|
|
14591
|
+
if (typeof val === "object" && val !== null) {
|
|
14592
|
+
if (seen.has(val))
|
|
14593
|
+
return "[Circular]";
|
|
14594
|
+
seen.add(val);
|
|
14595
|
+
}
|
|
14596
|
+
return val;
|
|
14597
|
+
}, condensed ? 0 : 2);
|
|
14598
|
+
if (condensed && json.length > maxLength) {
|
|
14599
|
+
return json.slice(0, maxLength) + "…";
|
|
14600
|
+
}
|
|
14601
|
+
return json;
|
|
14602
|
+
}
|
|
14603
|
+
catch {
|
|
14604
|
+
return "[unserializable details]";
|
|
14605
|
+
}
|
|
14606
|
+
}
|
|
14571
14607
|
/* ------------------------------------------------------------------ */
|
|
14572
|
-
/*
|
|
14608
|
+
/* IMPLEMENTATION */
|
|
14573
14609
|
/* ------------------------------------------------------------------ */
|
|
14574
14610
|
function getLogString(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
|
|
14575
14611
|
// ---------------- Normalize inputs ----------------
|
|
@@ -14603,28 +14639,15 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14603
14639
|
const finalLogType = resolvedLogType ?? "info";
|
|
14604
14640
|
const emoji = emojiMap[finalLogType] ?? "ℹ️";
|
|
14605
14641
|
const timestamp = new Date().toISOString();
|
|
14642
|
+
const condense = shouldCondense(finalLogType);
|
|
14643
|
+
if (condense && typeof resolvedFileLocation === "string") {
|
|
14644
|
+
resolvedFileLocation = resolvedFileLocation.split("/").pop();
|
|
14645
|
+
}
|
|
14606
14646
|
let line = `${emoji} [${timestamp}] [${resolvedFunctionName}] ${message}`;
|
|
14607
14647
|
// ---------------- Details serialization ----------------
|
|
14608
14648
|
if (resolvedDetails !== null && resolvedDetails !== undefined) {
|
|
14609
|
-
|
|
14610
|
-
|
|
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
|
-
}
|
|
14649
|
+
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
|
|
14650
|
+
line += ` | ${serialized}`;
|
|
14628
14651
|
}
|
|
14629
14652
|
line += ` | ${resolvedFileLocation}`;
|
|
14630
14653
|
// ---------------- Browser ----------------
|
|
@@ -14665,7 +14688,11 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14665
14688
|
return line;
|
|
14666
14689
|
}
|
|
14667
14690
|
|
|
14691
|
+
exports.IS_BROWSER = IS_BROWSER;
|
|
14692
|
+
exports.IS_NODE = IS_NODE;
|
|
14693
|
+
exports.LOG_CONFIG = LOG_CONFIG;
|
|
14668
14694
|
exports.getLogString = getLogString;
|
|
14669
14695
|
exports.logger = logger;
|
|
14670
14696
|
exports.resolveValue = resolveValue;
|
|
14697
|
+
exports.serializeDetails = serializeDetails;
|
|
14671
14698
|
//# sourceMappingURL=index.js.map
|