@putkoff/abstract-logger 0.0.65 → 0.0.73
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 +122 -60
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/imports/index.d.ts +5 -5
- package/dist/cjs/types/imports/utils/detect.d.ts +6 -1
- package/dist/cjs/types/imports/utils/index.d.ts +1 -0
- package/dist/cjs/types/imports/utils/loggerModes.d.ts +28 -0
- package/dist/cjs/types/logger/main/index.d.ts +0 -1
- package/dist/cjs/types/logger/main/loggerBench.d.ts +3 -13
- package/dist/esm/index.js +107 -53
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/imports/index.d.ts +5 -5
- package/dist/esm/types/imports/utils/detect.d.ts +6 -1
- package/dist/esm/types/imports/utils/index.d.ts +1 -0
- package/dist/esm/types/imports/utils/loggerModes.d.ts +28 -0
- package/dist/esm/types/logger/main/index.d.ts +0 -1
- package/dist/esm/types/logger/main/loggerBench.d.ts +3 -13
- package/dist/types/imports/index.d.ts +5 -5
- package/dist/types/imports/utils/detect.d.ts +6 -1
- package/dist/types/imports/utils/index.d.ts +1 -0
- package/dist/types/imports/utils/loggerModes.d.ts +28 -0
- package/dist/types/logger/main/index.d.ts +0 -1
- package/dist/types/logger/main/loggerBench.d.ts +3 -13
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -194,6 +194,17 @@ const IS_BROWSER = typeof window !== "undefined" &&
|
|
|
194
194
|
typeof window.document !== "undefined";
|
|
195
195
|
const IS_NODE = typeof process !== "undefined" &&
|
|
196
196
|
process.release?.name === "node";
|
|
197
|
+
const INTERNAL_FUNCTIONS = new Set([
|
|
198
|
+
"logit",
|
|
199
|
+
"logEvent",
|
|
200
|
+
"shouldLog",
|
|
201
|
+
"recordBenchSnapshot",
|
|
202
|
+
]);
|
|
203
|
+
const INTERNAL_FILES = [
|
|
204
|
+
"abstract-logger",
|
|
205
|
+
"loggerBench",
|
|
206
|
+
"blocker",
|
|
207
|
+
];
|
|
197
208
|
/* ------------------------------------------------------------------ */
|
|
198
209
|
/* Stack inspection */
|
|
199
210
|
/* ------------------------------------------------------------------ */
|
|
@@ -212,17 +223,29 @@ function extractFile(frame) {
|
|
|
212
223
|
return bareMatch[1];
|
|
213
224
|
return "unknown";
|
|
214
225
|
}
|
|
215
|
-
function getCallerInfo(
|
|
226
|
+
function getCallerInfo(skipExternal = 0) {
|
|
216
227
|
if (!IS_NODE) {
|
|
217
228
|
return { functionName: "browser", file: "browser" };
|
|
218
229
|
}
|
|
219
230
|
const obj = {};
|
|
220
|
-
Error.captureStackTrace(obj,
|
|
221
|
-
const stack = obj.stack?.split("\n") ?? [];
|
|
222
|
-
const
|
|
223
|
-
.
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
Error.captureStackTrace(obj, getCallerInfo);
|
|
232
|
+
const stack = obj.stack?.split("\n").slice(1) ?? [];
|
|
233
|
+
const externalFrames = stack.filter((line) => {
|
|
234
|
+
if (line.includes("node:internal"))
|
|
235
|
+
return false;
|
|
236
|
+
if (line.includes("processTicksAndRejections"))
|
|
237
|
+
return false;
|
|
238
|
+
for (const fn of INTERNAL_FUNCTIONS) {
|
|
239
|
+
if (line.includes(` ${fn} `) || line.includes(`.${fn}`))
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
for (const file of INTERNAL_FILES) {
|
|
243
|
+
if (line.includes(file))
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
});
|
|
248
|
+
const frame = externalFrames[skipExternal];
|
|
226
249
|
if (!frame) {
|
|
227
250
|
return { functionName: "unknown", file: "unknown" };
|
|
228
251
|
}
|
|
@@ -235,6 +258,59 @@ function getCallerInfo(func) {
|
|
|
235
258
|
file: extractFile(frame),
|
|
236
259
|
};
|
|
237
260
|
}
|
|
261
|
+
function getCheapCallerHint$1(opts) {
|
|
262
|
+
return {
|
|
263
|
+
functionName: opts.function_name ?? null,
|
|
264
|
+
file: opts.file_location ?? null,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
exports.LogMode = void 0;
|
|
269
|
+
(function (LogMode) {
|
|
270
|
+
LogMode["FULL"] = "full";
|
|
271
|
+
LogMode["CONSOLE"] = "console";
|
|
272
|
+
LogMode["COUNT"] = "count";
|
|
273
|
+
LogMode["OFF"] = "off";
|
|
274
|
+
})(exports.LogMode || (exports.LogMode = {}));
|
|
275
|
+
let mode = exports.LogMode.COUNT; // 🔒 DEFAULT FASTEST
|
|
276
|
+
let locked = false;
|
|
277
|
+
const LATENCY_BUCKETS = [1000n, 10000n, 100000n, 1000000n];
|
|
278
|
+
const stats = {
|
|
279
|
+
calls: 0,
|
|
280
|
+
totalNs: 0n,
|
|
281
|
+
byMode: {},
|
|
282
|
+
byType: {},
|
|
283
|
+
byFunction: {},
|
|
284
|
+
latency: {
|
|
285
|
+
buckets: LATENCY_BUCKETS.map(Number),
|
|
286
|
+
counts: new Array(LATENCY_BUCKETS.length + 1).fill(0),
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
function inc(map, key) {
|
|
290
|
+
if (!key)
|
|
291
|
+
return;
|
|
292
|
+
map[key] = (map[key] ?? 0) + 1;
|
|
293
|
+
}
|
|
294
|
+
function recordLatency(ns) {
|
|
295
|
+
let i = 0;
|
|
296
|
+
while (i < LATENCY_BUCKETS.length && ns > LATENCY_BUCKETS[i])
|
|
297
|
+
i++;
|
|
298
|
+
stats.latency.counts[i]++;
|
|
299
|
+
}
|
|
300
|
+
/* ---------------------------------- */
|
|
301
|
+
/* Mode control (LOCKED) */
|
|
302
|
+
/* ---------------------------------- */
|
|
303
|
+
function setLogMode(next) {
|
|
304
|
+
if (locked)
|
|
305
|
+
return;
|
|
306
|
+
mode = next;
|
|
307
|
+
}
|
|
308
|
+
function lockLogMode() {
|
|
309
|
+
locked = true;
|
|
310
|
+
}
|
|
311
|
+
function getLogMode() {
|
|
312
|
+
return mode;
|
|
313
|
+
}
|
|
238
314
|
|
|
239
315
|
const activityEmojiMap = {
|
|
240
316
|
emitting: "📤",
|
|
@@ -14864,14 +14940,6 @@ function formatLogLine({ emoji, timestamp, functionName, message, details, file,
|
|
|
14864
14940
|
return line;
|
|
14865
14941
|
}
|
|
14866
14942
|
|
|
14867
|
-
var LogMode;
|
|
14868
|
-
(function (LogMode) {
|
|
14869
|
-
LogMode["FULL"] = "full";
|
|
14870
|
-
LogMode["CONSOLE"] = "console";
|
|
14871
|
-
LogMode["COUNT"] = "count";
|
|
14872
|
-
LogMode["OFF"] = "off";
|
|
14873
|
-
})(LogMode || (LogMode = {}));
|
|
14874
|
-
|
|
14875
14943
|
const seen = new Map();
|
|
14876
14944
|
function hash(str) {
|
|
14877
14945
|
let h = 0;
|
|
@@ -14939,6 +15007,13 @@ function shouldLog(opts, caller) {
|
|
|
14939
15007
|
return true;
|
|
14940
15008
|
}
|
|
14941
15009
|
|
|
15010
|
+
// Object-style call
|
|
15011
|
+
function getCheapCallerHint(opts) {
|
|
15012
|
+
return {
|
|
15013
|
+
functionName: opts.function_name ?? null,
|
|
15014
|
+
file: opts.file_location ?? null,
|
|
15015
|
+
};
|
|
15016
|
+
}
|
|
14942
15017
|
function logit(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
|
|
14943
15018
|
/* -------------------------------------------------- */
|
|
14944
15019
|
/* Normalize inputs */
|
|
@@ -14957,7 +15032,18 @@ function logit(messageOrOptions, logType = null, details = null, function_name =
|
|
|
14957
15032
|
/* -------------------------------------------------- */
|
|
14958
15033
|
/* Caller info */
|
|
14959
15034
|
/* -------------------------------------------------- */
|
|
14960
|
-
|
|
15035
|
+
if (getLogMode() === exports.LogMode.OFF)
|
|
15036
|
+
return "";
|
|
15037
|
+
// 🔹 Phase 1: cheap decision
|
|
15038
|
+
const cheapCaller = getCheapCallerHint(opts);
|
|
15039
|
+
if (!shouldLog(opts, cheapCaller)) {
|
|
15040
|
+
return "";
|
|
15041
|
+
}
|
|
15042
|
+
// 🔹 Phase 2: expensive caller inspection (ONLY NOW)
|
|
15043
|
+
const caller = getCallerInfo();
|
|
15044
|
+
// 🔹 Phase 3: finalize names
|
|
15045
|
+
resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
|
|
15046
|
+
resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
|
|
14961
15047
|
/* -------------------------------------------------- */
|
|
14962
15048
|
/* 🔒 Single source of truth for logType */
|
|
14963
15049
|
/* -------------------------------------------------- */
|
|
@@ -15007,39 +15093,6 @@ function logit(messageOrOptions, logType = null, details = null, function_name =
|
|
|
15007
15093
|
}), finalLogType, resolvedLoggerInput);
|
|
15008
15094
|
}
|
|
15009
15095
|
|
|
15010
|
-
let mode = LogMode.COUNT; // 🔒 DEFAULT FASTEST
|
|
15011
|
-
const LATENCY_BUCKETS = [1000n, 10000n, 100000n, 1000000n];
|
|
15012
|
-
const stats = {
|
|
15013
|
-
calls: 0,
|
|
15014
|
-
totalNs: 0n,
|
|
15015
|
-
byMode: {},
|
|
15016
|
-
byType: {},
|
|
15017
|
-
byFunction: {},
|
|
15018
|
-
latency: {
|
|
15019
|
-
buckets: LATENCY_BUCKETS.map(Number),
|
|
15020
|
-
counts: new Array(LATENCY_BUCKETS.length + 1).fill(0),
|
|
15021
|
-
},
|
|
15022
|
-
};
|
|
15023
|
-
function inc(map, key) {
|
|
15024
|
-
if (!key)
|
|
15025
|
-
return;
|
|
15026
|
-
map[key] = (map[key] ?? 0) + 1;
|
|
15027
|
-
}
|
|
15028
|
-
function recordLatency(ns) {
|
|
15029
|
-
let i = 0;
|
|
15030
|
-
while (i < LATENCY_BUCKETS.length && ns > LATENCY_BUCKETS[i])
|
|
15031
|
-
i++;
|
|
15032
|
-
stats.latency.counts[i]++;
|
|
15033
|
-
}
|
|
15034
|
-
/* ---------------------------------- */
|
|
15035
|
-
/* Mode control (LOCKED) */
|
|
15036
|
-
/* ---------------------------------- */
|
|
15037
|
-
function setLogMode(next) {
|
|
15038
|
-
mode = next;
|
|
15039
|
-
}
|
|
15040
|
-
function getLogMode() {
|
|
15041
|
-
return mode;
|
|
15042
|
-
}
|
|
15043
15096
|
/* ---------------------------------- */
|
|
15044
15097
|
/* Stats */
|
|
15045
15098
|
/* ---------------------------------- */
|
|
@@ -15068,21 +15121,22 @@ function resetLogStats() {
|
|
|
15068
15121
|
/* ---------------------------------- */
|
|
15069
15122
|
function logEvent(props) {
|
|
15070
15123
|
stats.calls++;
|
|
15124
|
+
let mode = getLogMode();
|
|
15071
15125
|
// 🔥 OFF = absolute fastest
|
|
15072
|
-
if (mode === LogMode.OFF)
|
|
15126
|
+
if (mode === exports.LogMode.OFF)
|
|
15073
15127
|
return;
|
|
15074
15128
|
const type = typeof props?.logType === "string" ? props.logType : "info";
|
|
15075
15129
|
inc(stats.byMode, mode);
|
|
15076
15130
|
inc(stats.byType, type);
|
|
15077
15131
|
inc(stats.byFunction, props?.function_name);
|
|
15078
15132
|
// ⚡ COUNT = no timers, no I/O
|
|
15079
|
-
if (mode === LogMode.COUNT)
|
|
15133
|
+
if (mode === exports.LogMode.COUNT)
|
|
15080
15134
|
return;
|
|
15081
15135
|
const start = process.hrtime.bigint();
|
|
15082
|
-
if (mode === LogMode.FULL) {
|
|
15136
|
+
if (mode === exports.LogMode.FULL) {
|
|
15083
15137
|
logit(props);
|
|
15084
15138
|
}
|
|
15085
|
-
else if (mode === LogMode.CONSOLE) {
|
|
15139
|
+
else if (mode === exports.LogMode.CONSOLE) {
|
|
15086
15140
|
console.log(props);
|
|
15087
15141
|
}
|
|
15088
15142
|
const elapsed = process.hrtime.bigint() - start;
|
|
@@ -15091,25 +15145,25 @@ function logEvent(props) {
|
|
|
15091
15145
|
}
|
|
15092
15146
|
function setLogs(mode = null, interval = false, window_ms = null) {
|
|
15093
15147
|
const modes = [
|
|
15094
|
-
LogMode.FULL,
|
|
15095
|
-
LogMode.CONSOLE,
|
|
15096
|
-
LogMode.COUNT,
|
|
15097
|
-
LogMode.OFF,
|
|
15148
|
+
exports.LogMode.FULL,
|
|
15149
|
+
exports.LogMode.CONSOLE,
|
|
15150
|
+
exports.LogMode.COUNT,
|
|
15151
|
+
exports.LogMode.OFF,
|
|
15098
15152
|
];
|
|
15099
15153
|
if (window_ms != false) {
|
|
15100
15154
|
if (window_ms === true || window_ms == null) {
|
|
15101
|
-
window_ms =
|
|
15155
|
+
window_ms = 30_000;
|
|
15102
15156
|
}
|
|
15103
15157
|
}
|
|
15104
15158
|
if (interval != true) {
|
|
15105
|
-
mode = mode
|
|
15159
|
+
mode = mode ?? 3;
|
|
15106
15160
|
setLogMode(modes[mode]);
|
|
15107
15161
|
resetLogStats();
|
|
15108
15162
|
}
|
|
15109
15163
|
else {
|
|
15110
15164
|
let i = 0;
|
|
15111
15165
|
setInterval(() => {
|
|
15112
|
-
window_ms
|
|
15166
|
+
window_ms ||= 30_000;
|
|
15113
15167
|
recordBenchSnapshot(window_ms);
|
|
15114
15168
|
resetLogStats();
|
|
15115
15169
|
setLogMode(modes[++i % modes.length]);
|
|
@@ -15140,6 +15194,7 @@ function recordBenchSnapshot(windowMs) {
|
|
|
15140
15194
|
exports.COLS = COLS;
|
|
15141
15195
|
exports.IS_BROWSER = IS_BROWSER;
|
|
15142
15196
|
exports.IS_NODE = IS_NODE;
|
|
15197
|
+
exports.LATENCY_BUCKETS = LATENCY_BUCKETS;
|
|
15143
15198
|
exports.activityEmojiMap = activityEmojiMap;
|
|
15144
15199
|
exports.createLogger = winston.createLogger;
|
|
15145
15200
|
exports.debugLogConfig = debugLogConfig;
|
|
@@ -15147,19 +15202,26 @@ exports.extractFile = extractFile;
|
|
|
15147
15202
|
exports.format = winston.format;
|
|
15148
15203
|
exports.formatLogLine = formatLogLine;
|
|
15149
15204
|
exports.getCallerInfo = getCallerInfo;
|
|
15205
|
+
exports.getCheapCallerHint = getCheapCallerHint$1;
|
|
15150
15206
|
exports.getFinalLine = getFinalLine;
|
|
15151
15207
|
exports.getLogConfig = getLogConfig;
|
|
15208
|
+
exports.getLogMode = getLogMode;
|
|
15152
15209
|
exports.getLogString = logEvent;
|
|
15153
15210
|
exports.getNodeLogger = getNodeLogger;
|
|
15211
|
+
exports.inc = inc;
|
|
15212
|
+
exports.lockLogMode = lockLogMode;
|
|
15154
15213
|
exports.logger = logger;
|
|
15155
15214
|
exports.padLeft = padLeft;
|
|
15156
15215
|
exports.padRight = padRight;
|
|
15157
15216
|
exports.parseList = parseList;
|
|
15217
|
+
exports.recordLatency = recordLatency;
|
|
15158
15218
|
exports.resolveLogger = resolveLogger;
|
|
15159
15219
|
exports.resolveValue = resolveValue;
|
|
15160
15220
|
exports.serializeDetails = serializeDetails;
|
|
15221
|
+
exports.setLogMode = setLogMode;
|
|
15161
15222
|
exports.setLogs = setLogs;
|
|
15162
15223
|
exports.shouldCondense = shouldCondense;
|
|
15163
15224
|
exports.shouldShowDetails = shouldShowDetails;
|
|
15225
|
+
exports.stats = stats;
|
|
15164
15226
|
exports.transports = winston.transports;
|
|
15165
15227
|
//# sourceMappingURL=index.js.map
|