@putkoff/abstract-logger 0.0.34 โ 0.0.37
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 +373 -259
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/config.d.ts +4 -0
- package/dist/cjs/types/imports/constants.d.ts +8 -0
- package/dist/cjs/types/imports/functions.d.ts +16 -0
- package/dist/cjs/types/imports/index.d.ts +5 -0
- package/dist/cjs/types/imports/init_imports.d.ts +1 -0
- package/dist/cjs/types/imports/nodeLogger.d.ts +3 -0
- package/dist/cjs/types/imports/utils/detect.d.ts +10 -0
- package/dist/cjs/types/imports/utils/index.d.ts +2 -0
- package/dist/cjs/types/imports/utils/utils.d.ts +8 -0
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/cjs/types/logger/blocker.d.ts +4 -0
- package/dist/cjs/types/logger/logger.d.ts +1 -18
- package/dist/cjs/types/types/index.d.ts +1 -0
- package/dist/cjs/types/types/types.d.ts +10 -0
- package/dist/esm/index.js +361 -260
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/config.d.ts +4 -0
- package/dist/esm/types/imports/constants.d.ts +8 -0
- package/dist/esm/types/imports/functions.d.ts +16 -0
- package/dist/esm/types/imports/index.d.ts +5 -0
- package/dist/esm/types/imports/init_imports.d.ts +1 -0
- package/dist/esm/types/imports/nodeLogger.d.ts +3 -0
- package/dist/esm/types/imports/utils/detect.d.ts +10 -0
- package/dist/esm/types/imports/utils/index.d.ts +2 -0
- package/dist/esm/types/imports/utils/utils.d.ts +8 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/types/logger/blocker.d.ts +4 -0
- package/dist/esm/types/logger/logger.d.ts +1 -18
- package/dist/esm/types/types/index.d.ts +1 -0
- package/dist/esm/types/types/types.d.ts +10 -0
- package/dist/types/config.d.ts +4 -0
- package/dist/types/imports/constants.d.ts +8 -0
- package/dist/types/imports/functions.d.ts +16 -0
- package/dist/types/imports/index.d.ts +5 -0
- package/dist/types/imports/init_imports.d.ts +1 -0
- package/dist/types/imports/nodeLogger.d.ts +3 -0
- package/dist/types/imports/utils/detect.d.ts +10 -0
- package/dist/types/imports/utils/index.d.ts +2 -0
- package/dist/types/imports/utils/utils.d.ts +8 -0
- package/dist/types/index.d.ts +51 -11
- package/dist/types/logger/blocker.d.ts +4 -0
- package/dist/types/logger/logger.d.ts +1 -18
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/types.d.ts +10 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -10,7 +10,210 @@ import require$$1 from 'tty';
|
|
|
10
10
|
import require$$1$1 from 'string_decoder';
|
|
11
11
|
import require$$0$7 from 'http';
|
|
12
12
|
import require$$1$3 from 'https';
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
/* ------------------------------------------------------------------ */
|
|
15
|
+
/* Stack inspection */
|
|
16
|
+
/* ------------------------------------------------------------------ */
|
|
17
|
+
function padRight(str, width) {
|
|
18
|
+
return str.length >= width ? str : str + " ".repeat(width - str.length);
|
|
19
|
+
}
|
|
20
|
+
function padLeft(str, width) {
|
|
21
|
+
return str.length >= width ? str : " ".repeat(width - str.length) + str;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Normalizes inputs by treating "unknown" and empty values as null.
|
|
25
|
+
* Returns "unknown" ONLY if all inputs are invalid.
|
|
26
|
+
*/
|
|
27
|
+
function resolveValue(...values) {
|
|
28
|
+
let sawInput = false;
|
|
29
|
+
for (const value of values) {
|
|
30
|
+
if (value === undefined || value === null)
|
|
31
|
+
continue;
|
|
32
|
+
sawInput = true;
|
|
33
|
+
if (typeof value === "string") {
|
|
34
|
+
const v = value.trim();
|
|
35
|
+
if (!v || v.toLowerCase() === "unknown")
|
|
36
|
+
continue;
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
return sawInput ? "unknown" : "unknown";
|
|
42
|
+
}
|
|
43
|
+
function parseList(value) {
|
|
44
|
+
return value
|
|
45
|
+
? value.split(",").map(s => s.trim()).filter(Boolean)
|
|
46
|
+
: [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** ---------------------------------------------------------
|
|
50
|
+
* Detect Environment
|
|
51
|
+
* --------------------------------------------------------- */
|
|
52
|
+
const IS_BROWSER = typeof window !== "undefined" &&
|
|
53
|
+
typeof window.document !== "undefined";
|
|
54
|
+
const IS_NODE = typeof process !== "undefined" &&
|
|
55
|
+
process.release?.name === "node";
|
|
56
|
+
/* ------------------------------------------------------------------ */
|
|
57
|
+
/* Stack inspection */
|
|
58
|
+
/* ------------------------------------------------------------------ */
|
|
59
|
+
function extractFile(frame) {
|
|
60
|
+
// file:///path/to/file.ts:line:col
|
|
61
|
+
const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
|
|
62
|
+
if (esmMatch)
|
|
63
|
+
return esmMatch[1];
|
|
64
|
+
// (path/to/file.ts:line:col)
|
|
65
|
+
const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
|
|
66
|
+
if (cjsMatch)
|
|
67
|
+
return cjsMatch[1];
|
|
68
|
+
// at path/to/file.ts:line:col
|
|
69
|
+
const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
|
|
70
|
+
if (bareMatch)
|
|
71
|
+
return bareMatch[1];
|
|
72
|
+
return "unknown";
|
|
73
|
+
}
|
|
74
|
+
function getCallerInfo(func) {
|
|
75
|
+
if (!IS_NODE) {
|
|
76
|
+
return { functionName: "browser", file: "browser" };
|
|
77
|
+
}
|
|
78
|
+
const obj = {};
|
|
79
|
+
Error.captureStackTrace(obj, func);
|
|
80
|
+
const stack = obj.stack?.split("\n") ?? [];
|
|
81
|
+
const frame = stack
|
|
82
|
+
.slice(1)
|
|
83
|
+
.find((line) => !line.includes("node:internal") &&
|
|
84
|
+
!line.includes("processTicksAndRejections"));
|
|
85
|
+
if (!frame) {
|
|
86
|
+
return { functionName: "unknown", file: "unknown" };
|
|
87
|
+
}
|
|
88
|
+
const fnMatch = frame.match(/at\s+async\s+([^\s(]+)/) ||
|
|
89
|
+
frame.match(/at\s+([^\s(]+)/);
|
|
90
|
+
return {
|
|
91
|
+
functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
|
|
92
|
+
? fnMatch[1]
|
|
93
|
+
: "unknown",
|
|
94
|
+
file: extractFile(frame),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const activityEmojiMap = {
|
|
99
|
+
emitting: "๐ค",
|
|
100
|
+
ingesting: "๐ฅ",
|
|
101
|
+
streaming: "๐",
|
|
102
|
+
forwarding: "โก๏ธ",
|
|
103
|
+
receiving: "๐ก",
|
|
104
|
+
relaying: "๐",
|
|
105
|
+
syncing: "๐",
|
|
106
|
+
buffering: "โณ",
|
|
107
|
+
batching: "๐ฆ",
|
|
108
|
+
dispatching: "๐",
|
|
109
|
+
settings: "โ๏ธ",
|
|
110
|
+
computing: "๐ง ",
|
|
111
|
+
running: "๐",
|
|
112
|
+
working: "๐ง",
|
|
113
|
+
building: "๐๏ธ",
|
|
114
|
+
compiling: "๐งฉ",
|
|
115
|
+
crunching: "๐งฎ",
|
|
116
|
+
optimizing: "๐",
|
|
117
|
+
queued: "๐",
|
|
118
|
+
waiting: "โณ",
|
|
119
|
+
active: "โถ๏ธ",
|
|
120
|
+
paused: "โธ๏ธ",
|
|
121
|
+
sleeping: "๐ค",
|
|
122
|
+
resumed: "๐",
|
|
123
|
+
completed: "โ
",
|
|
124
|
+
cancelled: "โ",
|
|
125
|
+
expired: "โ",
|
|
126
|
+
warning: "โ ๏ธ",
|
|
127
|
+
error: "โ",
|
|
128
|
+
critical: "๐จ",
|
|
129
|
+
retrying: "๐",
|
|
130
|
+
skipped: "โญ๏ธ",
|
|
131
|
+
fallback: "๐",
|
|
132
|
+
degraded: "๐",
|
|
133
|
+
saved: "๐พ",
|
|
134
|
+
loading: "๐",
|
|
135
|
+
exporting: "๐ค",
|
|
136
|
+
importing: "๐ฅ",
|
|
137
|
+
archived: "๐๏ธ",
|
|
138
|
+
deleted: "๐๏ธ",
|
|
139
|
+
cached: "๐ง",
|
|
140
|
+
persisted: "๐",
|
|
141
|
+
locked: "๐",
|
|
142
|
+
unlocked: "๐",
|
|
143
|
+
secure: "๐ก๏ธ",
|
|
144
|
+
insecure: "โ ๏ธ",
|
|
145
|
+
verified: "โ๏ธ",
|
|
146
|
+
blocked: "โ",
|
|
147
|
+
allowed: "๐ข",
|
|
148
|
+
connected: "๐",
|
|
149
|
+
disconnected: "โ",
|
|
150
|
+
online: "๐ข",
|
|
151
|
+
offline: "๐ด",
|
|
152
|
+
latency: "๐ถ",
|
|
153
|
+
proxying: "๐งญ",
|
|
154
|
+
broadcasting: "๐ฃ",
|
|
155
|
+
thinking: "๐ค",
|
|
156
|
+
learning: "๐ง ",
|
|
157
|
+
predicting: "๐ฎ",
|
|
158
|
+
scanning: "๐",
|
|
159
|
+
crawling: "๐ท๏ธ",
|
|
160
|
+
responding: "๐ฌ",
|
|
161
|
+
generating: "โจ",
|
|
162
|
+
debug: "๐",
|
|
163
|
+
trace: "๐งต",
|
|
164
|
+
inspect: "๐",
|
|
165
|
+
test: "๐งช",
|
|
166
|
+
mock: "๐ญ",
|
|
167
|
+
sandbox: "๐๏ธ",
|
|
168
|
+
experiment: "โ๏ธ",
|
|
169
|
+
success: "โ
",
|
|
170
|
+
processing: "๐",
|
|
171
|
+
listening: "๐ก",
|
|
172
|
+
prune: "๐งน",
|
|
173
|
+
connect: "๐",
|
|
174
|
+
info: "โน๏ธ",
|
|
175
|
+
warn: "โ ๏ธ"
|
|
176
|
+
};
|
|
177
|
+
const COLS = {
|
|
178
|
+
emoji: 2,
|
|
179
|
+
timestamp: 24,
|
|
180
|
+
function: 28,
|
|
181
|
+
message: 0, // flexible
|
|
182
|
+
file: 16,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/* ------------------------------------------------------------------ */
|
|
186
|
+
/* Winston logger (Node only) */
|
|
187
|
+
/* ------------------------------------------------------------------ */
|
|
188
|
+
console.log("ENV CHECK:", {
|
|
189
|
+
LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
|
|
190
|
+
LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
|
|
191
|
+
});
|
|
192
|
+
function getLogConfig() {
|
|
193
|
+
return {
|
|
194
|
+
condensed: process.env.LOG_CONDENSED !== "false",
|
|
195
|
+
expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
|
|
196
|
+
showDetails: process.env.LOG_SHOW_DETAILS !== "false",
|
|
197
|
+
maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
|
|
198
|
+
activityBlocklist: parse$1(process.env.LOG_ACTIVITY_BLOCKLIST),
|
|
199
|
+
logTypeBlocklist: parse$1(process.env.LOG_TYPE_BLOCKLIST),
|
|
200
|
+
sampleRate: Number(process.env.LOG_SAMPLE_RATE ?? 1), // 0โ1
|
|
201
|
+
// ๐ NEW
|
|
202
|
+
prettyDetails: process.env.LOG_PRETTY_DETAILS === "true",
|
|
203
|
+
showDetailslist: process.env.LOG_DETAILS_ALLOWLIST
|
|
204
|
+
? process.env.LOG_DETAILS_ALLOWLIST.split(",").map(s => s.trim())
|
|
205
|
+
: [],
|
|
206
|
+
functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
|
|
207
|
+
? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
|
|
208
|
+
: [],
|
|
209
|
+
functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
|
|
210
|
+
? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
|
|
211
|
+
: [],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function parse$1(v) {
|
|
215
|
+
return v ? v.split(",").map(s => s.trim()) : [];
|
|
216
|
+
}
|
|
14
217
|
|
|
15
218
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
16
219
|
|
|
@@ -3219,14 +3422,14 @@ var fecha = {
|
|
|
3219
3422
|
};
|
|
3220
3423
|
|
|
3221
3424
|
var fecha$1 = /*#__PURE__*/Object.freeze({
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3425
|
+
__proto__: null,
|
|
3426
|
+
assign: assign,
|
|
3427
|
+
default: fecha,
|
|
3428
|
+
defaultI18n: defaultI18n,
|
|
3429
|
+
format: format$1,
|
|
3430
|
+
parse: parse,
|
|
3431
|
+
setGlobalDateI18n: setGlobalDateI18n,
|
|
3432
|
+
setGlobalDateMasks: setGlobalDateMasks
|
|
3230
3433
|
});
|
|
3231
3434
|
|
|
3232
3435
|
var require$$0 = /*@__PURE__*/getAugmentedNamespace(fecha$1);
|
|
@@ -14460,138 +14663,70 @@ var container = class Container {
|
|
|
14460
14663
|
warn.forProperties(exports$1, 'deprecated', ['emitErrs', 'levelLength']);
|
|
14461
14664
|
} (winston));
|
|
14462
14665
|
|
|
14463
|
-
|
|
14464
|
-
|
|
14465
|
-
|
|
14466
|
-
const IS_BROWSER = typeof window !== "undefined" &&
|
|
14467
|
-
typeof window.document !== "undefined";
|
|
14468
|
-
const IS_NODE = typeof process !== "undefined" &&
|
|
14469
|
-
process.release?.name === "node";
|
|
14470
|
-
|
|
14471
|
-
function getLogConfig() {
|
|
14472
|
-
return {
|
|
14473
|
-
condensed: process.env.LOG_CONDENSED !== "false",
|
|
14474
|
-
expandOnDebug: process.env.LOG_EXPAND_DEBUG !== "false",
|
|
14475
|
-
showDetails: process.env.LOG_SHOW_DETAILS !== "false",
|
|
14476
|
-
maxDetailsLength: Number(process.env.LOG_DETAILS_MAX ?? 500),
|
|
14477
|
-
showDetailslist: process.env.LOG_DETAILS_ALLOWLIST
|
|
14478
|
-
? process.env.LOG_DETAILS_ALLOWLIST.split(",").map(s => s.trim())
|
|
14479
|
-
: [],
|
|
14480
|
-
functionAllowlist: process.env.LOG_FUNCTION_ALLOWLIST
|
|
14481
|
-
? process.env.LOG_FUNCTION_ALLOWLIST.split(",").map(s => s.trim())
|
|
14482
|
-
: [],
|
|
14483
|
-
functionBlocklist: process.env.LOG_FUNCTION_BLOCKLIST
|
|
14484
|
-
? process.env.LOG_FUNCTION_BLOCKLIST.split(",").map(s => s.trim())
|
|
14485
|
-
: [],
|
|
14486
|
-
};
|
|
14487
|
-
}
|
|
14488
|
-
|
|
14666
|
+
/* ------------------------------------------------------------------ */
|
|
14667
|
+
/* Winston logger (Node only) */
|
|
14668
|
+
/* ------------------------------------------------------------------ */
|
|
14489
14669
|
console.log("ENV CHECK:", {
|
|
14490
14670
|
LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
|
|
14491
14671
|
LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
|
|
14492
14672
|
});
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14501
|
-
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14506
|
-
}
|
|
14507
|
-
function shouldCondense(logType) {
|
|
14508
|
-
const LOG_CONFIG = getLogConfig();
|
|
14509
|
-
if (LOG_CONFIG.expandOnDebug && logType === "debug") {
|
|
14510
|
-
return false;
|
|
14673
|
+
function getNodeLogger() {
|
|
14674
|
+
let nodeLogger = null;
|
|
14675
|
+
if (IS_NODE) {
|
|
14676
|
+
nodeLogger = winston.createLogger({
|
|
14677
|
+
level: "info",
|
|
14678
|
+
format: winston.format.combine(winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.errors({ stack: true }), winston.format.printf(({ timestamp, level, message, stack }) => {
|
|
14679
|
+
return `${timestamp} [${level}] ${message}${stack ? "\n" + stack : ""}`;
|
|
14680
|
+
})),
|
|
14681
|
+
transports: [
|
|
14682
|
+
new winston.transports.Console(),
|
|
14683
|
+
new winston.transports.File({ filename: "logs/error.log", level: "error" }),
|
|
14684
|
+
new winston.transports.File({ filename: "logs/combined.log" }),
|
|
14685
|
+
],
|
|
14686
|
+
});
|
|
14511
14687
|
}
|
|
14512
|
-
return
|
|
14688
|
+
return nodeLogger;
|
|
14513
14689
|
}
|
|
14514
|
-
|
|
14515
|
-
|
|
14516
|
-
|
|
14517
|
-
|
|
14690
|
+
const logger = getNodeLogger();
|
|
14691
|
+
function getFinalLine(line, finalLogType, resolvedLoggerInput) {
|
|
14692
|
+
// ---------------- Browser ----------------
|
|
14693
|
+
if (IS_BROWSER) {
|
|
14694
|
+
console[finalLogType === "error"
|
|
14695
|
+
? "error"
|
|
14696
|
+
: finalLogType === "warn"
|
|
14697
|
+
? "warn"
|
|
14698
|
+
: finalLogType === "debug"
|
|
14699
|
+
? "debug"
|
|
14700
|
+
: "log"](line);
|
|
14701
|
+
return line;
|
|
14518
14702
|
}
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
* Normalizes inputs by treating "unknown" and empty values as null.
|
|
14525
|
-
* Returns "unknown" ONLY if all inputs are invalid.
|
|
14526
|
-
*/
|
|
14527
|
-
function resolveValue(...values) {
|
|
14528
|
-
let sawInput = false;
|
|
14529
|
-
for (const value of values) {
|
|
14530
|
-
if (value === undefined || value === null)
|
|
14531
|
-
continue;
|
|
14532
|
-
sawInput = true;
|
|
14533
|
-
if (typeof value === "string") {
|
|
14534
|
-
const v = value.trim();
|
|
14535
|
-
if (!v || v.toLowerCase() === "unknown")
|
|
14536
|
-
continue;
|
|
14537
|
-
return value;
|
|
14538
|
-
}
|
|
14539
|
-
return value;
|
|
14703
|
+
// ---------------- Node ----------------
|
|
14704
|
+
const activeLogger = resolveLogger(resolvedLoggerInput);
|
|
14705
|
+
if (!activeLogger) {
|
|
14706
|
+
console.log(line);
|
|
14707
|
+
return line;
|
|
14540
14708
|
}
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
/* Stack inspection */
|
|
14556
|
-
/* ------------------------------------------------------------------ */
|
|
14557
|
-
function extractFile(frame) {
|
|
14558
|
-
// file:///path/to/file.ts:line:col
|
|
14559
|
-
const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
|
|
14560
|
-
if (esmMatch)
|
|
14561
|
-
return esmMatch[1];
|
|
14562
|
-
// (path/to/file.ts:line:col)
|
|
14563
|
-
const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
|
|
14564
|
-
if (cjsMatch)
|
|
14565
|
-
return cjsMatch[1];
|
|
14566
|
-
// at path/to/file.ts:line:col
|
|
14567
|
-
const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
|
|
14568
|
-
if (bareMatch)
|
|
14569
|
-
return bareMatch[1];
|
|
14570
|
-
return "unknown";
|
|
14571
|
-
}
|
|
14572
|
-
function getCallerInfo() {
|
|
14573
|
-
if (!IS_NODE) {
|
|
14574
|
-
return { functionName: "browser", file: "browser" };
|
|
14709
|
+
try {
|
|
14710
|
+
switch (finalLogType) {
|
|
14711
|
+
case "error":
|
|
14712
|
+
activeLogger.error(line);
|
|
14713
|
+
break;
|
|
14714
|
+
case "warn":
|
|
14715
|
+
activeLogger.warn(line);
|
|
14716
|
+
break;
|
|
14717
|
+
case "debug":
|
|
14718
|
+
activeLogger.debug(line);
|
|
14719
|
+
break;
|
|
14720
|
+
default:
|
|
14721
|
+
activeLogger.info(line);
|
|
14722
|
+
}
|
|
14575
14723
|
}
|
|
14576
|
-
|
|
14577
|
-
|
|
14578
|
-
const stack = obj.stack?.split("\n") ?? [];
|
|
14579
|
-
const frame = stack
|
|
14580
|
-
.slice(1)
|
|
14581
|
-
.find((line) => !line.includes("node:internal") &&
|
|
14582
|
-
!line.includes("processTicksAndRejections"));
|
|
14583
|
-
if (!frame) {
|
|
14584
|
-
return { functionName: "unknown", file: "unknown" };
|
|
14724
|
+
catch {
|
|
14725
|
+
console.log(line);
|
|
14585
14726
|
}
|
|
14586
|
-
|
|
14587
|
-
frame.match(/at\s+([^\s(]+)/);
|
|
14588
|
-
return {
|
|
14589
|
-
functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
|
|
14590
|
-
? fnMatch[1]
|
|
14591
|
-
: "unknown",
|
|
14592
|
-
file: extractFile(frame),
|
|
14593
|
-
};
|
|
14727
|
+
return line;
|
|
14594
14728
|
}
|
|
14729
|
+
|
|
14595
14730
|
/* ------------------------------------------------------------------ */
|
|
14596
14731
|
/* Safe logger resolver */
|
|
14597
14732
|
/* ------------------------------------------------------------------ */
|
|
@@ -14608,7 +14743,22 @@ function resolveLogger(candidate) {
|
|
|
14608
14743
|
}
|
|
14609
14744
|
return null;
|
|
14610
14745
|
}
|
|
14611
|
-
function
|
|
14746
|
+
function shouldCondense(logType) {
|
|
14747
|
+
const LOG_CONFIG = getLogConfig();
|
|
14748
|
+
if (LOG_CONFIG.expandOnDebug && logType === "debug") {
|
|
14749
|
+
return false;
|
|
14750
|
+
}
|
|
14751
|
+
return LOG_CONFIG.condensed;
|
|
14752
|
+
}
|
|
14753
|
+
function shouldShowDetails(logType) {
|
|
14754
|
+
const cfg = getLogConfig();
|
|
14755
|
+
if (cfg.showDetailslist.length > 0) {
|
|
14756
|
+
return cfg.showDetailslist.includes(logType);
|
|
14757
|
+
}
|
|
14758
|
+
return cfg.showDetails;
|
|
14759
|
+
}
|
|
14760
|
+
function serializeDetails(value, condensed, maxLength, pretty // ๐ new
|
|
14761
|
+
) {
|
|
14612
14762
|
try {
|
|
14613
14763
|
const seen = new WeakSet();
|
|
14614
14764
|
const json = JSON.stringify(value, (key, val) => {
|
|
@@ -14622,7 +14772,8 @@ function serializeDetails(value, condensed, maxLength) {
|
|
|
14622
14772
|
seen.add(val);
|
|
14623
14773
|
}
|
|
14624
14774
|
return val;
|
|
14625
|
-
}, condensed ?
|
|
14775
|
+
}, pretty && !condensed ? 2 : 0 // ๐ HERE
|
|
14776
|
+
);
|
|
14626
14777
|
if (condensed && json.length > maxLength) {
|
|
14627
14778
|
return json.slice(0, maxLength) + "โฆ";
|
|
14628
14779
|
}
|
|
@@ -14632,6 +14783,71 @@ function serializeDetails(value, condensed, maxLength) {
|
|
|
14632
14783
|
return "[unserializable details]";
|
|
14633
14784
|
}
|
|
14634
14785
|
}
|
|
14786
|
+
function formatLogLine({ emoji, timestamp, functionName, message, details, file, condense, maxDetailsLength, pretty }) {
|
|
14787
|
+
let line = `${padRight(emoji, 3)}` +
|
|
14788
|
+
`[${padRight(timestamp, COLS.timestamp)}] ` +
|
|
14789
|
+
`[${functionName}] ` +
|
|
14790
|
+
`${message}`;
|
|
14791
|
+
if (details !== undefined) {
|
|
14792
|
+
const serialized = serializeDetails(details, condense, maxDetailsLength, pretty);
|
|
14793
|
+
line += ` | ${serialized}`;
|
|
14794
|
+
}
|
|
14795
|
+
line += ` | ${padRight(file, COLS.file)}`;
|
|
14796
|
+
return line;
|
|
14797
|
+
}
|
|
14798
|
+
|
|
14799
|
+
const seen = new Map();
|
|
14800
|
+
function hash(str) {
|
|
14801
|
+
let h = 0;
|
|
14802
|
+
for (let i = 0; i < str.length; i++) {
|
|
14803
|
+
h = (h << 5) - h + str.charCodeAt(i);
|
|
14804
|
+
h |= 0;
|
|
14805
|
+
}
|
|
14806
|
+
return Math.abs(h);
|
|
14807
|
+
}
|
|
14808
|
+
function shouldLog(opts, caller) {
|
|
14809
|
+
const cfg = getLogConfig();
|
|
14810
|
+
const fn = caller.functionName;
|
|
14811
|
+
const type = opts.logType ?? "info";
|
|
14812
|
+
const activity = opts.activity;
|
|
14813
|
+
const message = opts.message;
|
|
14814
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14815
|
+
// 1๏ธโฃ Hard allowlist (strongest gate)
|
|
14816
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14817
|
+
if (cfg.functionAllowlist.length > 0) {
|
|
14818
|
+
if (!cfg.functionAllowlist.includes(fn))
|
|
14819
|
+
return false;
|
|
14820
|
+
}
|
|
14821
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14822
|
+
// 2๏ธโฃ Hard blocklists
|
|
14823
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14824
|
+
if (cfg.functionBlocklist.includes(fn))
|
|
14825
|
+
return false;
|
|
14826
|
+
if (activity && cfg.activityBlocklist.includes(activity))
|
|
14827
|
+
return false;
|
|
14828
|
+
if (cfg.logTypeBlocklist.includes(type))
|
|
14829
|
+
return false;
|
|
14830
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14831
|
+
// 3๏ธโฃ Burst protection (debug spam)
|
|
14832
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14833
|
+
if (type === "debug") {
|
|
14834
|
+
const key = fn + ":" + message;
|
|
14835
|
+
const count = (seen.get(key) ?? 0) + 1;
|
|
14836
|
+
seen.set(key, count);
|
|
14837
|
+
if (count > 5)
|
|
14838
|
+
return false; // drop after 5 identical logs
|
|
14839
|
+
}
|
|
14840
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14841
|
+
// 4๏ธโฃ Deterministic sampling
|
|
14842
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
14843
|
+
if (cfg.sampleRate < 1) {
|
|
14844
|
+
const pct = (hash(fn) % 100) / 100;
|
|
14845
|
+
if (pct > cfg.sampleRate)
|
|
14846
|
+
return false;
|
|
14847
|
+
}
|
|
14848
|
+
return true;
|
|
14849
|
+
}
|
|
14850
|
+
|
|
14635
14851
|
/* ------------------------------------------------------------------ */
|
|
14636
14852
|
/* IMPLEMENTATION */
|
|
14637
14853
|
/* ------------------------------------------------------------------ */
|
|
@@ -14655,97 +14871,16 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14655
14871
|
}
|
|
14656
14872
|
let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
|
|
14657
14873
|
// ---------------- Resolve caller info ----------------
|
|
14658
|
-
const
|
|
14659
|
-
|
|
14660
|
-
|
|
14661
|
-
const { functionName } = getCallerInfo();
|
|
14662
|
-
resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
|
|
14663
|
-
}
|
|
14664
|
-
if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
|
|
14665
|
-
const { file } = getCallerInfo();
|
|
14666
|
-
resolvedFileLocation = resolveValue(file, resolvedFileLocation);
|
|
14874
|
+
const caller = getCallerInfo(getLogString);
|
|
14875
|
+
if (!shouldLog(opts, caller)) {
|
|
14876
|
+
return ""; // ๐ blocked โ nothing emitted
|
|
14667
14877
|
}
|
|
14668
|
-
|
|
14669
|
-
|
|
14670
|
-
|
|
14671
|
-
streaming: "๐",
|
|
14672
|
-
forwarding: "โก๏ธ",
|
|
14673
|
-
receiving: "๐ก",
|
|
14674
|
-
relaying: "๐",
|
|
14675
|
-
syncing: "๐",
|
|
14676
|
-
buffering: "โณ",
|
|
14677
|
-
batching: "๐ฆ",
|
|
14678
|
-
dispatching: "๐",
|
|
14679
|
-
settings: "โ๏ธ",
|
|
14680
|
-
computing: "๐ง ",
|
|
14681
|
-
running: "๐",
|
|
14682
|
-
working: "๐ง",
|
|
14683
|
-
building: "๐๏ธ",
|
|
14684
|
-
compiling: "๐งฉ",
|
|
14685
|
-
crunching: "๐งฎ",
|
|
14686
|
-
optimizing: "๐",
|
|
14687
|
-
queued: "๐",
|
|
14688
|
-
waiting: "โณ",
|
|
14689
|
-
active: "โถ๏ธ",
|
|
14690
|
-
paused: "โธ๏ธ",
|
|
14691
|
-
sleeping: "๐ค",
|
|
14692
|
-
resumed: "๐",
|
|
14693
|
-
completed: "โ
",
|
|
14694
|
-
cancelled: "โ",
|
|
14695
|
-
expired: "โ",
|
|
14696
|
-
warning: "โ ๏ธ",
|
|
14697
|
-
error: "โ",
|
|
14698
|
-
critical: "๐จ",
|
|
14699
|
-
retrying: "๐",
|
|
14700
|
-
skipped: "โญ๏ธ",
|
|
14701
|
-
fallback: "๐",
|
|
14702
|
-
degraded: "๐",
|
|
14703
|
-
saved: "๐พ",
|
|
14704
|
-
loading: "๐",
|
|
14705
|
-
exporting: "๐ค",
|
|
14706
|
-
importing: "๐ฅ",
|
|
14707
|
-
archived: "๐๏ธ",
|
|
14708
|
-
deleted: "๐๏ธ",
|
|
14709
|
-
cached: "๐ง",
|
|
14710
|
-
persisted: "๐",
|
|
14711
|
-
locked: "๐",
|
|
14712
|
-
unlocked: "๐",
|
|
14713
|
-
secure: "๐ก๏ธ",
|
|
14714
|
-
insecure: "โ ๏ธ",
|
|
14715
|
-
verified: "โ๏ธ",
|
|
14716
|
-
blocked: "โ",
|
|
14717
|
-
allowed: "๐ข",
|
|
14718
|
-
connected: "๐",
|
|
14719
|
-
disconnected: "โ",
|
|
14720
|
-
online: "๐ข",
|
|
14721
|
-
offline: "๐ด",
|
|
14722
|
-
latency: "๐ถ",
|
|
14723
|
-
proxying: "๐งญ",
|
|
14724
|
-
broadcasting: "๐ฃ",
|
|
14725
|
-
thinking: "๐ค",
|
|
14726
|
-
learning: "๐ง ",
|
|
14727
|
-
predicting: "๐ฎ",
|
|
14728
|
-
scanning: "๐",
|
|
14729
|
-
crawling: "๐ท๏ธ",
|
|
14730
|
-
responding: "๐ฌ",
|
|
14731
|
-
generating: "โจ",
|
|
14732
|
-
debug: "๐",
|
|
14733
|
-
trace: "๐งต",
|
|
14734
|
-
inspect: "๐",
|
|
14735
|
-
test: "๐งช",
|
|
14736
|
-
mock: "๐ญ",
|
|
14737
|
-
sandbox: "๐๏ธ",
|
|
14738
|
-
experiment: "โ๏ธ",
|
|
14739
|
-
success: "โ
",
|
|
14740
|
-
processing: "๐",
|
|
14741
|
-
listening: "๐ก",
|
|
14742
|
-
prune: "๐งน",
|
|
14743
|
-
connect: "๐",
|
|
14744
|
-
info: "โน๏ธ",
|
|
14745
|
-
warn: "โ ๏ธ"
|
|
14746
|
-
};
|
|
14878
|
+
// ---------------- Resolve caller info ----------------
|
|
14879
|
+
resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
|
|
14880
|
+
resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
|
|
14747
14881
|
const finalLogType = resolvedLogType ?? "info";
|
|
14748
|
-
const emoji =
|
|
14882
|
+
const emoji = activityEmojiMap[opts.activity ?? ""] ??
|
|
14883
|
+
"โน๏ธ";
|
|
14749
14884
|
const timestamp = new Date().toISOString();
|
|
14750
14885
|
const condense = shouldCondense(finalLogType);
|
|
14751
14886
|
const showDetails = shouldShowDetails(finalLogType);
|
|
@@ -14754,7 +14889,7 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14754
14889
|
}
|
|
14755
14890
|
const emojiCol = padRight(emoji, 3);
|
|
14756
14891
|
const ts = padRight(timestamp, COLS.timestamp);
|
|
14757
|
-
const fn =
|
|
14892
|
+
const fn = resolvedFunctionName;
|
|
14758
14893
|
const fileName = padRight(resolvedFileLocation.trim(), COLS.file);
|
|
14759
14894
|
let line = `${emojiCol}` +
|
|
14760
14895
|
`[${ts}] ` +
|
|
@@ -14762,47 +14897,13 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14762
14897
|
`${message}`;
|
|
14763
14898
|
if (showDetails && resolvedDetails !== null && resolvedDetails !== undefined) {
|
|
14764
14899
|
const LOG_CONFIG = getLogConfig();
|
|
14765
|
-
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength
|
|
14900
|
+
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength, LOG_CONFIG.prettyDetails // ๐ HERE
|
|
14901
|
+
);
|
|
14766
14902
|
line += ` | ${serialized}`;
|
|
14767
14903
|
}
|
|
14768
14904
|
line += ` | ${fileName}`;
|
|
14769
|
-
|
|
14770
|
-
if (IS_BROWSER) {
|
|
14771
|
-
console[finalLogType === "error"
|
|
14772
|
-
? "error"
|
|
14773
|
-
: finalLogType === "warn"
|
|
14774
|
-
? "warn"
|
|
14775
|
-
: finalLogType === "debug"
|
|
14776
|
-
? "debug"
|
|
14777
|
-
: "log"](line);
|
|
14778
|
-
return line;
|
|
14779
|
-
}
|
|
14780
|
-
// ---------------- Node ----------------
|
|
14781
|
-
const activeLogger = resolveLogger(resolvedLoggerInput);
|
|
14782
|
-
if (!activeLogger) {
|
|
14783
|
-
console.log(line);
|
|
14784
|
-
return line;
|
|
14785
|
-
}
|
|
14786
|
-
try {
|
|
14787
|
-
switch (finalLogType) {
|
|
14788
|
-
case "error":
|
|
14789
|
-
activeLogger.error(line);
|
|
14790
|
-
break;
|
|
14791
|
-
case "warn":
|
|
14792
|
-
activeLogger.warn(line);
|
|
14793
|
-
break;
|
|
14794
|
-
case "debug":
|
|
14795
|
-
activeLogger.debug(line);
|
|
14796
|
-
break;
|
|
14797
|
-
default:
|
|
14798
|
-
activeLogger.info(line);
|
|
14799
|
-
}
|
|
14800
|
-
}
|
|
14801
|
-
catch {
|
|
14802
|
-
console.log(line);
|
|
14803
|
-
}
|
|
14804
|
-
return line;
|
|
14905
|
+
return getFinalLine(line, finalLogType, resolvedLoggerInput);
|
|
14805
14906
|
}
|
|
14806
14907
|
|
|
14807
|
-
export { IS_BROWSER, IS_NODE, getLogConfig, getLogString, logger, resolveValue, serializeDetails };
|
|
14908
|
+
export { COLS, IS_BROWSER, IS_NODE, activityEmojiMap, extractFile, formatLogLine, getCallerInfo, getFinalLine, getLogConfig, getLogString, getNodeLogger, logger, padLeft, padRight, parseList, resolveLogger, resolveValue, serializeDetails, shouldCondense, shouldShowDetails };
|
|
14808
14909
|
//# sourceMappingURL=index.js.map
|