@putkoff/abstract-logger 0.0.62 → 0.0.63
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 +76 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/logger/index.d.ts +1 -1
- package/dist/esm/index.js +76 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/logger/index.d.ts +1 -1
- package/dist/types/logger/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -15032,6 +15032,38 @@ function recordLatency(ns) {
|
|
|
15032
15032
|
stats.latency.counts[i]++;
|
|
15033
15033
|
}
|
|
15034
15034
|
/* ---------------------------------- */
|
|
15035
|
+
/* Mode control (LOCKED) */
|
|
15036
|
+
/* ---------------------------------- */
|
|
15037
|
+
function setLogMode(next) {
|
|
15038
|
+
mode = next;
|
|
15039
|
+
}
|
|
15040
|
+
function getLogMode() {
|
|
15041
|
+
return mode;
|
|
15042
|
+
}
|
|
15043
|
+
/* ---------------------------------- */
|
|
15044
|
+
/* Stats */
|
|
15045
|
+
/* ---------------------------------- */
|
|
15046
|
+
function getLogStats() {
|
|
15047
|
+
return {
|
|
15048
|
+
calls: stats.calls,
|
|
15049
|
+
avgNs: stats.calls === 0
|
|
15050
|
+
? 0
|
|
15051
|
+
: Number(stats.totalNs / BigInt(stats.calls)),
|
|
15052
|
+
byMode: stats.byMode,
|
|
15053
|
+
byType: stats.byType,
|
|
15054
|
+
byFunction: stats.byFunction,
|
|
15055
|
+
latency: stats.latency,
|
|
15056
|
+
};
|
|
15057
|
+
}
|
|
15058
|
+
function resetLogStats() {
|
|
15059
|
+
stats.calls = 0;
|
|
15060
|
+
stats.totalNs = 0n;
|
|
15061
|
+
stats.byMode = {};
|
|
15062
|
+
stats.byType = {};
|
|
15063
|
+
stats.byFunction = {};
|
|
15064
|
+
stats.latency.counts.fill(0);
|
|
15065
|
+
}
|
|
15066
|
+
/* ---------------------------------- */
|
|
15035
15067
|
/* Unified logging entry point */
|
|
15036
15068
|
/* ---------------------------------- */
|
|
15037
15069
|
function logEvent(props) {
|
|
@@ -15057,11 +15089,53 @@ function logEvent(props) {
|
|
|
15057
15089
|
stats.totalNs += elapsed;
|
|
15058
15090
|
recordLatency(elapsed);
|
|
15059
15091
|
}
|
|
15092
|
+
function setLogs(mode = null, interval = false, window_ms = null) {
|
|
15093
|
+
const modes = [
|
|
15094
|
+
LogMode.FULL,
|
|
15095
|
+
LogMode.CONSOLE,
|
|
15096
|
+
LogMode.COUNT,
|
|
15097
|
+
LogMode.OFF,
|
|
15098
|
+
];
|
|
15099
|
+
if (window_ms != false) {
|
|
15100
|
+
if (window_ms === true || window_ms == null) {
|
|
15101
|
+
window_ms = 30000;
|
|
15102
|
+
}
|
|
15103
|
+
}
|
|
15104
|
+
if (interval != true) {
|
|
15105
|
+
mode = mode || 3;
|
|
15106
|
+
setLogMode(modes[mode]);
|
|
15107
|
+
resetLogStats();
|
|
15108
|
+
}
|
|
15109
|
+
else {
|
|
15110
|
+
let i = 0;
|
|
15111
|
+
setInterval(() => {
|
|
15112
|
+
window_ms || (window_ms = 30000);
|
|
15113
|
+
recordBenchSnapshot(window_ms);
|
|
15114
|
+
resetLogStats();
|
|
15115
|
+
setLogMode(modes[++i % modes.length]);
|
|
15116
|
+
}, window_ms);
|
|
15117
|
+
}
|
|
15118
|
+
}
|
|
15060
15119
|
|
|
15061
15120
|
const LOG_DIR = process.env.LOG_BENCH_DIR ??
|
|
15062
15121
|
path.resolve(process.cwd(), "log-bench");
|
|
15063
|
-
path.join(LOG_DIR, "bench.ndjson");
|
|
15122
|
+
const FILE = path.join(LOG_DIR, "bench.ndjson");
|
|
15064
15123
|
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
15124
|
+
function recordBenchSnapshot(windowMs) {
|
|
15125
|
+
const stats = getLogStats();
|
|
15126
|
+
const record = {
|
|
15127
|
+
ts: new Date().toISOString(),
|
|
15128
|
+
windowMs,
|
|
15129
|
+
mode: getLogMode(),
|
|
15130
|
+
calls: stats.calls,
|
|
15131
|
+
avgNs: stats.avgNs,
|
|
15132
|
+
byMode: stats.byMode,
|
|
15133
|
+
byType: stats.byType,
|
|
15134
|
+
byFunction: stats.byFunction,
|
|
15135
|
+
latency: stats.latency,
|
|
15136
|
+
};
|
|
15137
|
+
fs.appendFileSync(FILE, JSON.stringify(record) + "\n");
|
|
15138
|
+
}
|
|
15065
15139
|
|
|
15066
15140
|
exports.COLS = COLS;
|
|
15067
15141
|
exports.IS_BROWSER = IS_BROWSER;
|
|
@@ -15084,6 +15158,7 @@ exports.parseList = parseList;
|
|
|
15084
15158
|
exports.resolveLogger = resolveLogger;
|
|
15085
15159
|
exports.resolveValue = resolveValue;
|
|
15086
15160
|
exports.serializeDetails = serializeDetails;
|
|
15161
|
+
exports.setLogs = setLogs;
|
|
15087
15162
|
exports.shouldCondense = shouldCondense;
|
|
15088
15163
|
exports.shouldShowDetails = shouldShowDetails;
|
|
15089
15164
|
exports.transports = winston.transports;
|