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