@putkoff/abstract-logger 0.0.19 → 0.0.21
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 +66 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/config.d.ts +12 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/cjs/types/logger/logger.d.ts +1 -0
- package/dist/esm/index.js +63 -22
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/config.d.ts +12 -0
- package/dist/esm/types/index.d.ts +2 -0
- package/dist/esm/types/logger/logger.d.ts +1 -0
- package/dist/types/config.d.ts +12 -0
- package/dist/types/index.d.ts +21 -1
- package/dist/types/logger/logger.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const LOG_CONFIG: {
|
|
2
|
+
condensed: boolean;
|
|
3
|
+
expandOnDebug: boolean;
|
|
4
|
+
maxDetailsLength: number;
|
|
5
|
+
/**
|
|
6
|
+
* Function-level filtering
|
|
7
|
+
* - empty allowlist = allow all
|
|
8
|
+
* - blocklist always wins
|
|
9
|
+
*/
|
|
10
|
+
functionAllowlist: string[];
|
|
11
|
+
functionBlocklist: string[];
|
|
12
|
+
};
|
|
@@ -14,5 +14,6 @@ export interface LogStringOptions {
|
|
|
14
14
|
file_location?: any;
|
|
15
15
|
consumerLogger?: any;
|
|
16
16
|
}
|
|
17
|
+
export declare function serializeDetails(value: any, condensed: boolean, maxLength: number): string;
|
|
17
18
|
export declare function getLogString(options: LogStringOptions): string;
|
|
18
19
|
export declare function getLogString(messageOrOptions: string | LogStringOptions, logType?: LogType, details?: any, function_name?: any, file_location?: any, consumerLogger?: any): string;
|
package/dist/esm/index.js
CHANGED
|
@@ -14467,6 +14467,23 @@ const IS_BROWSER = typeof window !== "undefined" &&
|
|
|
14467
14467
|
const IS_NODE = typeof process !== "undefined" &&
|
|
14468
14468
|
process.release?.name === "node";
|
|
14469
14469
|
|
|
14470
|
+
const LOG_CONFIG = {
|
|
14471
|
+
condensed: process.env.LOG_CONDENSED !== "false",
|
|
14472
|
+
expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
|
|
14473
|
+
maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
|
|
14474
|
+
/**
|
|
14475
|
+
* Function-level filtering
|
|
14476
|
+
* - empty allowlist = allow all
|
|
14477
|
+
* - blocklist always wins
|
|
14478
|
+
*/
|
|
14479
|
+
functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
|
|
14480
|
+
? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
|
|
14481
|
+
: [],
|
|
14482
|
+
functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
|
|
14483
|
+
? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
|
|
14484
|
+
: [],
|
|
14485
|
+
};
|
|
14486
|
+
|
|
14470
14487
|
/* ------------------------------------------------------------------ */
|
|
14471
14488
|
/* Winston logger (Node only) */
|
|
14472
14489
|
/* ------------------------------------------------------------------ */
|
|
@@ -14484,6 +14501,12 @@ if (IS_NODE) {
|
|
|
14484
14501
|
],
|
|
14485
14502
|
});
|
|
14486
14503
|
}
|
|
14504
|
+
function shouldCondense(logType) {
|
|
14505
|
+
if (LOG_CONFIG.expandOnDebug && logType === "debug") {
|
|
14506
|
+
return false;
|
|
14507
|
+
}
|
|
14508
|
+
return LOG_CONFIG.condensed;
|
|
14509
|
+
}
|
|
14487
14510
|
/** Exported logger */
|
|
14488
14511
|
const logger = nodeLogger;
|
|
14489
14512
|
/**
|
|
@@ -14566,6 +14589,30 @@ function resolveLogger(candidate) {
|
|
|
14566
14589
|
}
|
|
14567
14590
|
return null;
|
|
14568
14591
|
}
|
|
14592
|
+
function serializeDetails(value, condensed, maxLength) {
|
|
14593
|
+
try {
|
|
14594
|
+
const seen = new WeakSet();
|
|
14595
|
+
const json = JSON.stringify(value, (key, val) => {
|
|
14596
|
+
if (typeof val === "function")
|
|
14597
|
+
return undefined;
|
|
14598
|
+
if (typeof val === "bigint")
|
|
14599
|
+
return val.toString();
|
|
14600
|
+
if (typeof val === "object" && val !== null) {
|
|
14601
|
+
if (seen.has(val))
|
|
14602
|
+
return "[Circular]";
|
|
14603
|
+
seen.add(val);
|
|
14604
|
+
}
|
|
14605
|
+
return val;
|
|
14606
|
+
}, condensed ? 0 : 2);
|
|
14607
|
+
if (condensed && json.length > maxLength) {
|
|
14608
|
+
return json.slice(0, maxLength) + "…";
|
|
14609
|
+
}
|
|
14610
|
+
return json;
|
|
14611
|
+
}
|
|
14612
|
+
catch {
|
|
14613
|
+
return "[unserializable details]";
|
|
14614
|
+
}
|
|
14615
|
+
}
|
|
14569
14616
|
/* ------------------------------------------------------------------ */
|
|
14570
14617
|
/* IMPLEMENTATION */
|
|
14571
14618
|
/* ------------------------------------------------------------------ */
|
|
@@ -14590,8 +14637,15 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14590
14637
|
let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
|
|
14591
14638
|
// ---------------- Resolve caller info ----------------
|
|
14592
14639
|
const { functionName, file } = getCallerInfo();
|
|
14593
|
-
|
|
14594
|
-
|
|
14640
|
+
// ---------------- Resolve caller info ----------------
|
|
14641
|
+
if (!resolvedFunctionName || resolvedFunctionName === "unknown") {
|
|
14642
|
+
const { functionName } = getCallerInfo();
|
|
14643
|
+
resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
|
|
14644
|
+
}
|
|
14645
|
+
if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
|
|
14646
|
+
const { file } = getCallerInfo();
|
|
14647
|
+
resolvedFileLocation = resolveValue(file, resolvedFileLocation);
|
|
14648
|
+
}
|
|
14595
14649
|
const emojiMap = {
|
|
14596
14650
|
info: "ℹ️",
|
|
14597
14651
|
warn: "⚠️",
|
|
@@ -14601,28 +14655,15 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14601
14655
|
const finalLogType = resolvedLogType ?? "info";
|
|
14602
14656
|
const emoji = emojiMap[finalLogType] ?? "ℹ️";
|
|
14603
14657
|
const timestamp = new Date().toISOString();
|
|
14658
|
+
const condense = shouldCondense(finalLogType);
|
|
14659
|
+
if (condense) {
|
|
14660
|
+
resolvedFileLocation = resolvedFileLocation.split("/").pop();
|
|
14661
|
+
}
|
|
14604
14662
|
let line = `${emoji} [${timestamp}] [${resolvedFunctionName}] ${message}`;
|
|
14605
14663
|
// ---------------- Details serialization ----------------
|
|
14606
14664
|
if (resolvedDetails !== null && resolvedDetails !== undefined) {
|
|
14607
|
-
|
|
14608
|
-
|
|
14609
|
-
const safe = JSON.stringify(resolvedDetails, (key, value) => {
|
|
14610
|
-
if (typeof value === "function")
|
|
14611
|
-
return undefined;
|
|
14612
|
-
if (typeof value === "bigint")
|
|
14613
|
-
return value.toString();
|
|
14614
|
-
if (typeof value === "object" && value !== null) {
|
|
14615
|
-
if (seen.has(value))
|
|
14616
|
-
return "[Circular]";
|
|
14617
|
-
seen.add(value);
|
|
14618
|
-
}
|
|
14619
|
-
return value;
|
|
14620
|
-
}, 2);
|
|
14621
|
-
line += ` | ${safe}`;
|
|
14622
|
-
}
|
|
14623
|
-
catch {
|
|
14624
|
-
line += ` | [unserializable details]`;
|
|
14625
|
-
}
|
|
14665
|
+
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength);
|
|
14666
|
+
line += ` | ${serialized}`;
|
|
14626
14667
|
}
|
|
14627
14668
|
line += ` | ${resolvedFileLocation}`;
|
|
14628
14669
|
// ---------------- Browser ----------------
|
|
@@ -14663,5 +14704,5 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14663
14704
|
return line;
|
|
14664
14705
|
}
|
|
14665
14706
|
|
|
14666
|
-
export { getLogString, logger, resolveValue };
|
|
14707
|
+
export { IS_BROWSER, IS_NODE, LOG_CONFIG, getLogString, logger, resolveValue, serializeDetails };
|
|
14667
14708
|
//# sourceMappingURL=index.js.map
|