@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type LogType = "info" | "warn" | "error" | "debug" | null;
|
|
1
|
+
export type LogType = "info" | "warn" | "error" | "debug" | null;
|
|
2
2
|
/** Exported logger */
|
|
3
3
|
export declare const logger: any;
|
|
4
4
|
/**
|
|
@@ -6,5 +6,13 @@ export declare const logger: any;
|
|
|
6
6
|
* Returns "unknown" ONLY if all inputs are invalid.
|
|
7
7
|
*/
|
|
8
8
|
export declare function resolveValue<T = string>(...values: Array<T | string | null | undefined>): T | "unknown";
|
|
9
|
+
export interface LogStringOptions {
|
|
10
|
+
message: string;
|
|
11
|
+
logType?: LogType;
|
|
12
|
+
details?: any;
|
|
13
|
+
function_name?: any;
|
|
14
|
+
file_location?: any;
|
|
15
|
+
consumerLogger?: any;
|
|
16
|
+
}
|
|
17
|
+
export declare function getLogString(options: LogStringOptions): string;
|
|
9
18
|
export declare function getLogString(message: string, logType?: LogType, details?: any, function_name?: any, file_location?: any, consumerLogger?: any): string;
|
|
10
|
-
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -14569,24 +14569,44 @@ function resolveLogger(candidate) {
|
|
|
14569
14569
|
/* ------------------------------------------------------------------ */
|
|
14570
14570
|
/* UNIVERSAL getLogString (cannot crash) */
|
|
14571
14571
|
/* ------------------------------------------------------------------ */
|
|
14572
|
-
function getLogString(
|
|
14573
|
-
|
|
14574
|
-
|
|
14575
|
-
|
|
14572
|
+
function getLogString(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
|
|
14573
|
+
// ---------------- Normalize inputs ----------------
|
|
14574
|
+
let opts;
|
|
14575
|
+
if (typeof messageOrOptions === "object" && messageOrOptions !== null) {
|
|
14576
|
+
// Dict-style
|
|
14577
|
+
opts = messageOrOptions;
|
|
14578
|
+
}
|
|
14579
|
+
else {
|
|
14580
|
+
// Positional-style
|
|
14581
|
+
opts = {
|
|
14582
|
+
message: messageOrOptions,
|
|
14583
|
+
logType,
|
|
14584
|
+
details,
|
|
14585
|
+
function_name,
|
|
14586
|
+
file_location,
|
|
14587
|
+
consumerLogger,
|
|
14588
|
+
};
|
|
14589
|
+
}
|
|
14590
|
+
let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
|
|
14591
|
+
// ---------------- Resolve caller info ----------------
|
|
14592
|
+
const { functionName, file } = getCallerInfo();
|
|
14593
|
+
resolvedFunctionName = resolveValue(functionName !== "unknown" ? functionName : null, resolvedFunctionName);
|
|
14594
|
+
resolvedFileLocation = resolveValue(file !== "unknown" ? file : null, resolvedFileLocation);
|
|
14576
14595
|
const emojiMap = {
|
|
14577
14596
|
info: "ℹ️",
|
|
14578
14597
|
warn: "⚠️",
|
|
14579
14598
|
error: "❌",
|
|
14580
14599
|
debug: "🔍",
|
|
14581
14600
|
};
|
|
14582
|
-
|
|
14583
|
-
const emoji = emojiMap[
|
|
14601
|
+
const finalLogType = resolvedLogType ?? "info";
|
|
14602
|
+
const emoji = emojiMap[finalLogType] ?? "ℹ️";
|
|
14584
14603
|
const timestamp = new Date().toISOString();
|
|
14585
|
-
let line = `${emoji} [${timestamp}] [${
|
|
14586
|
-
|
|
14604
|
+
let line = `${emoji} [${timestamp}] [${resolvedFunctionName}] ${message}`;
|
|
14605
|
+
// ---------------- Details serialization ----------------
|
|
14606
|
+
if (resolvedDetails !== null && resolvedDetails !== undefined) {
|
|
14587
14607
|
try {
|
|
14588
14608
|
const seen = new WeakSet();
|
|
14589
|
-
const safe = JSON.stringify(
|
|
14609
|
+
const safe = JSON.stringify(resolvedDetails, (key, value) => {
|
|
14590
14610
|
if (typeof value === "function")
|
|
14591
14611
|
return undefined;
|
|
14592
14612
|
if (typeof value === "bigint")
|
|
@@ -14604,22 +14624,26 @@ function getLogString(message, logType = null, details = null, function_name = n
|
|
|
14604
14624
|
line += ` | [unserializable details]`;
|
|
14605
14625
|
}
|
|
14606
14626
|
}
|
|
14607
|
-
line += ` | ${
|
|
14608
|
-
|
|
14627
|
+
line += ` | ${resolvedFileLocation}`;
|
|
14628
|
+
// ---------------- Browser ----------------
|
|
14609
14629
|
if (IS_BROWSER) {
|
|
14610
|
-
console[
|
|
14611
|
-
|
|
14612
|
-
|
|
14630
|
+
console[finalLogType === "error"
|
|
14631
|
+
? "error"
|
|
14632
|
+
: finalLogType === "warn"
|
|
14633
|
+
? "warn"
|
|
14634
|
+
: finalLogType === "debug"
|
|
14635
|
+
? "debug"
|
|
14636
|
+
: "log"](line);
|
|
14613
14637
|
return line;
|
|
14614
14638
|
}
|
|
14615
|
-
|
|
14616
|
-
const activeLogger = resolveLogger(
|
|
14639
|
+
// ---------------- Node ----------------
|
|
14640
|
+
const activeLogger = resolveLogger(resolvedLoggerInput);
|
|
14617
14641
|
if (!activeLogger) {
|
|
14618
14642
|
console.log(line);
|
|
14619
14643
|
return line;
|
|
14620
14644
|
}
|
|
14621
14645
|
try {
|
|
14622
|
-
switch (
|
|
14646
|
+
switch (finalLogType) {
|
|
14623
14647
|
case "error":
|
|
14624
14648
|
activeLogger.error(line);
|
|
14625
14649
|
break;
|