@putkoff/abstract-logger 0.0.35 โ 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 +372 -257
- 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 +360 -258
- 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,137 +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
|
-
/* ------------------------------------------------------------------ */
|
|
14558
|
-
function extractFile(frame) {
|
|
14559
|
-
// file:///path/to/file.ts:line:col
|
|
14560
|
-
const esmMatch = frame.match(/file:\/\/(.+?):\d+:\d+/);
|
|
14561
|
-
if (esmMatch)
|
|
14562
|
-
return esmMatch[1];
|
|
14563
|
-
// (path/to/file.ts:line:col)
|
|
14564
|
-
const cjsMatch = frame.match(/\((.+?):\d+:\d+\)/);
|
|
14565
|
-
if (cjsMatch)
|
|
14566
|
-
return cjsMatch[1];
|
|
14567
|
-
// at path/to/file.ts:line:col
|
|
14568
|
-
const bareMatch = frame.match(/at\s+(.+?):\d+:\d+/);
|
|
14569
|
-
if (bareMatch)
|
|
14570
|
-
return bareMatch[1];
|
|
14571
|
-
return "unknown";
|
|
14572
|
-
}
|
|
14573
|
-
function getCallerInfo() {
|
|
14574
|
-
if (!IS_NODE) {
|
|
14575
|
-
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
|
+
}
|
|
14576
14725
|
}
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
const stack = obj.stack?.split("\n") ?? [];
|
|
14580
|
-
const frame = stack
|
|
14581
|
-
.slice(1)
|
|
14582
|
-
.find((line) => !line.includes("node:internal") &&
|
|
14583
|
-
!line.includes("processTicksAndRejections"));
|
|
14584
|
-
if (!frame) {
|
|
14585
|
-
return { functionName: "unknown", file: "unknown" };
|
|
14726
|
+
catch {
|
|
14727
|
+
console.log(line);
|
|
14586
14728
|
}
|
|
14587
|
-
|
|
14588
|
-
frame.match(/at\s+([^\s(]+)/);
|
|
14589
|
-
return {
|
|
14590
|
-
functionName: fnMatch?.[1] && fnMatch[1] !== "Object.<anonymous>"
|
|
14591
|
-
? fnMatch[1]
|
|
14592
|
-
: "unknown",
|
|
14593
|
-
file: extractFile(frame),
|
|
14594
|
-
};
|
|
14729
|
+
return line;
|
|
14595
14730
|
}
|
|
14731
|
+
|
|
14596
14732
|
/* ------------------------------------------------------------------ */
|
|
14597
14733
|
/* Safe logger resolver */
|
|
14598
14734
|
/* ------------------------------------------------------------------ */
|
|
@@ -14609,7 +14745,22 @@ function resolveLogger(candidate) {
|
|
|
14609
14745
|
}
|
|
14610
14746
|
return null;
|
|
14611
14747
|
}
|
|
14612
|
-
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
|
+
) {
|
|
14613
14764
|
try {
|
|
14614
14765
|
const seen = new WeakSet();
|
|
14615
14766
|
const json = JSON.stringify(value, (key, val) => {
|
|
@@ -14623,7 +14774,8 @@ function serializeDetails(value, condensed, maxLength) {
|
|
|
14623
14774
|
seen.add(val);
|
|
14624
14775
|
}
|
|
14625
14776
|
return val;
|
|
14626
|
-
}, condensed ?
|
|
14777
|
+
}, pretty && !condensed ? 2 : 0 // ๐ HERE
|
|
14778
|
+
);
|
|
14627
14779
|
if (condensed && json.length > maxLength) {
|
|
14628
14780
|
return json.slice(0, maxLength) + "โฆ";
|
|
14629
14781
|
}
|
|
@@ -14633,6 +14785,71 @@ function serializeDetails(value, condensed, maxLength) {
|
|
|
14633
14785
|
return "[unserializable details]";
|
|
14634
14786
|
}
|
|
14635
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
|
+
|
|
14636
14853
|
/* ------------------------------------------------------------------ */
|
|
14637
14854
|
/* IMPLEMENTATION */
|
|
14638
14855
|
/* ------------------------------------------------------------------ */
|
|
@@ -14656,97 +14873,16 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14656
14873
|
}
|
|
14657
14874
|
let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
|
|
14658
14875
|
// ---------------- Resolve caller info ----------------
|
|
14659
|
-
const
|
|
14660
|
-
|
|
14661
|
-
|
|
14662
|
-
const { functionName } = getCallerInfo();
|
|
14663
|
-
resolvedFunctionName = resolveValue(functionName, resolvedFunctionName);
|
|
14664
|
-
}
|
|
14665
|
-
if (!resolvedFileLocation || resolvedFileLocation === "unknown") {
|
|
14666
|
-
const { file } = getCallerInfo();
|
|
14667
|
-
resolvedFileLocation = resolveValue(file, resolvedFileLocation);
|
|
14876
|
+
const caller = getCallerInfo(getLogString);
|
|
14877
|
+
if (!shouldLog(opts, caller)) {
|
|
14878
|
+
return ""; // ๐ blocked โ nothing emitted
|
|
14668
14879
|
}
|
|
14669
|
-
|
|
14670
|
-
|
|
14671
|
-
|
|
14672
|
-
streaming: "๐",
|
|
14673
|
-
forwarding: "โก๏ธ",
|
|
14674
|
-
receiving: "๐ก",
|
|
14675
|
-
relaying: "๐",
|
|
14676
|
-
syncing: "๐",
|
|
14677
|
-
buffering: "โณ",
|
|
14678
|
-
batching: "๐ฆ",
|
|
14679
|
-
dispatching: "๐",
|
|
14680
|
-
settings: "โ๏ธ",
|
|
14681
|
-
computing: "๐ง ",
|
|
14682
|
-
running: "๐",
|
|
14683
|
-
working: "๐ง",
|
|
14684
|
-
building: "๐๏ธ",
|
|
14685
|
-
compiling: "๐งฉ",
|
|
14686
|
-
crunching: "๐งฎ",
|
|
14687
|
-
optimizing: "๐",
|
|
14688
|
-
queued: "๐",
|
|
14689
|
-
waiting: "โณ",
|
|
14690
|
-
active: "โถ๏ธ",
|
|
14691
|
-
paused: "โธ๏ธ",
|
|
14692
|
-
sleeping: "๐ค",
|
|
14693
|
-
resumed: "๐",
|
|
14694
|
-
completed: "โ
",
|
|
14695
|
-
cancelled: "โ",
|
|
14696
|
-
expired: "โ",
|
|
14697
|
-
warning: "โ ๏ธ",
|
|
14698
|
-
error: "โ",
|
|
14699
|
-
critical: "๐จ",
|
|
14700
|
-
retrying: "๐",
|
|
14701
|
-
skipped: "โญ๏ธ",
|
|
14702
|
-
fallback: "๐",
|
|
14703
|
-
degraded: "๐",
|
|
14704
|
-
saved: "๐พ",
|
|
14705
|
-
loading: "๐",
|
|
14706
|
-
exporting: "๐ค",
|
|
14707
|
-
importing: "๐ฅ",
|
|
14708
|
-
archived: "๐๏ธ",
|
|
14709
|
-
deleted: "๐๏ธ",
|
|
14710
|
-
cached: "๐ง",
|
|
14711
|
-
persisted: "๐",
|
|
14712
|
-
locked: "๐",
|
|
14713
|
-
unlocked: "๐",
|
|
14714
|
-
secure: "๐ก๏ธ",
|
|
14715
|
-
insecure: "โ ๏ธ",
|
|
14716
|
-
verified: "โ๏ธ",
|
|
14717
|
-
blocked: "โ",
|
|
14718
|
-
allowed: "๐ข",
|
|
14719
|
-
connected: "๐",
|
|
14720
|
-
disconnected: "โ",
|
|
14721
|
-
online: "๐ข",
|
|
14722
|
-
offline: "๐ด",
|
|
14723
|
-
latency: "๐ถ",
|
|
14724
|
-
proxying: "๐งญ",
|
|
14725
|
-
broadcasting: "๐ฃ",
|
|
14726
|
-
thinking: "๐ค",
|
|
14727
|
-
learning: "๐ง ",
|
|
14728
|
-
predicting: "๐ฎ",
|
|
14729
|
-
scanning: "๐",
|
|
14730
|
-
crawling: "๐ท๏ธ",
|
|
14731
|
-
responding: "๐ฌ",
|
|
14732
|
-
generating: "โจ",
|
|
14733
|
-
debug: "๐",
|
|
14734
|
-
trace: "๐งต",
|
|
14735
|
-
inspect: "๐",
|
|
14736
|
-
test: "๐งช",
|
|
14737
|
-
mock: "๐ญ",
|
|
14738
|
-
sandbox: "๐๏ธ",
|
|
14739
|
-
experiment: "โ๏ธ",
|
|
14740
|
-
success: "โ
",
|
|
14741
|
-
processing: "๐",
|
|
14742
|
-
listening: "๐ก",
|
|
14743
|
-
prune: "๐งน",
|
|
14744
|
-
connect: "๐",
|
|
14745
|
-
info: "โน๏ธ",
|
|
14746
|
-
warn: "โ ๏ธ"
|
|
14747
|
-
};
|
|
14880
|
+
// ---------------- Resolve caller info ----------------
|
|
14881
|
+
resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
|
|
14882
|
+
resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
|
|
14748
14883
|
const finalLogType = resolvedLogType ?? "info";
|
|
14749
|
-
const emoji =
|
|
14884
|
+
const emoji = activityEmojiMap[opts.activity ?? ""] ??
|
|
14885
|
+
"โน๏ธ";
|
|
14750
14886
|
const timestamp = new Date().toISOString();
|
|
14751
14887
|
const condense = shouldCondense(finalLogType);
|
|
14752
14888
|
const showDetails = shouldShowDetails(finalLogType);
|
|
@@ -14763,53 +14899,32 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14763
14899
|
`${message}`;
|
|
14764
14900
|
if (showDetails && resolvedDetails !== null && resolvedDetails !== undefined) {
|
|
14765
14901
|
const LOG_CONFIG = getLogConfig();
|
|
14766
|
-
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength
|
|
14902
|
+
const serialized = serializeDetails(resolvedDetails, condense, LOG_CONFIG.maxDetailsLength, LOG_CONFIG.prettyDetails // ๐ HERE
|
|
14903
|
+
);
|
|
14767
14904
|
line += ` | ${serialized}`;
|
|
14768
14905
|
}
|
|
14769
14906
|
line += ` | ${fileName}`;
|
|
14770
|
-
|
|
14771
|
-
if (IS_BROWSER) {
|
|
14772
|
-
console[finalLogType === "error"
|
|
14773
|
-
? "error"
|
|
14774
|
-
: finalLogType === "warn"
|
|
14775
|
-
? "warn"
|
|
14776
|
-
: finalLogType === "debug"
|
|
14777
|
-
? "debug"
|
|
14778
|
-
: "log"](line);
|
|
14779
|
-
return line;
|
|
14780
|
-
}
|
|
14781
|
-
// ---------------- Node ----------------
|
|
14782
|
-
const activeLogger = resolveLogger(resolvedLoggerInput);
|
|
14783
|
-
if (!activeLogger) {
|
|
14784
|
-
console.log(line);
|
|
14785
|
-
return line;
|
|
14786
|
-
}
|
|
14787
|
-
try {
|
|
14788
|
-
switch (finalLogType) {
|
|
14789
|
-
case "error":
|
|
14790
|
-
activeLogger.error(line);
|
|
14791
|
-
break;
|
|
14792
|
-
case "warn":
|
|
14793
|
-
activeLogger.warn(line);
|
|
14794
|
-
break;
|
|
14795
|
-
case "debug":
|
|
14796
|
-
activeLogger.debug(line);
|
|
14797
|
-
break;
|
|
14798
|
-
default:
|
|
14799
|
-
activeLogger.info(line);
|
|
14800
|
-
}
|
|
14801
|
-
}
|
|
14802
|
-
catch {
|
|
14803
|
-
console.log(line);
|
|
14804
|
-
}
|
|
14805
|
-
return line;
|
|
14907
|
+
return getFinalLine(line, finalLogType, resolvedLoggerInput);
|
|
14806
14908
|
}
|
|
14807
14909
|
|
|
14910
|
+
exports.COLS = COLS;
|
|
14808
14911
|
exports.IS_BROWSER = IS_BROWSER;
|
|
14809
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;
|
|
14810
14918
|
exports.getLogConfig = getLogConfig;
|
|
14811
14919
|
exports.getLogString = getLogString;
|
|
14920
|
+
exports.getNodeLogger = getNodeLogger;
|
|
14812
14921
|
exports.logger = logger;
|
|
14922
|
+
exports.padLeft = padLeft;
|
|
14923
|
+
exports.padRight = padRight;
|
|
14924
|
+
exports.parseList = parseList;
|
|
14925
|
+
exports.resolveLogger = resolveLogger;
|
|
14813
14926
|
exports.resolveValue = resolveValue;
|
|
14814
14927
|
exports.serializeDetails = serializeDetails;
|
|
14928
|
+
exports.shouldCondense = shouldCondense;
|
|
14929
|
+
exports.shouldShowDetails = shouldShowDetails;
|
|
14815
14930
|
//# sourceMappingURL=index.js.map
|