@putkoff/abstract-logger 0.0.59 → 0.0.62
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 +211 -144
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/imports/functions.d.ts +1 -1
- package/dist/cjs/types/imports/index.d.ts +1 -1
- package/dist/cjs/types/imports/utils/index.d.ts +2 -2
- package/dist/cjs/types/index.d.ts +4 -4
- package/dist/cjs/types/logger/index.d.ts +1 -1
- package/dist/cjs/types/logger/logit/blocker.d.ts +4 -0
- package/dist/cjs/types/logger/logit/index.d.ts +1 -0
- package/dist/cjs/types/logger/logit/logger.d.ts +3 -0
- package/dist/cjs/types/logger/main/index.d.ts +3 -0
- package/dist/cjs/types/logger/main/loggerBench.d.ts +24 -0
- package/dist/cjs/types/logger/main/loggerBenchRecorder.d.ts +1 -0
- package/dist/cjs/types/logger/main/loggerModes.d.ts +6 -0
- package/dist/cjs/types/types/index.d.ts +1 -1
- package/dist/esm/index.js +210 -143
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/imports/functions.d.ts +1 -1
- package/dist/esm/types/imports/index.d.ts +1 -1
- package/dist/esm/types/imports/utils/index.d.ts +2 -2
- package/dist/esm/types/index.d.ts +4 -4
- package/dist/esm/types/logger/index.d.ts +1 -1
- package/dist/esm/types/logger/logit/blocker.d.ts +4 -0
- package/dist/esm/types/logger/logit/index.d.ts +1 -0
- package/dist/esm/types/logger/logit/logger.d.ts +3 -0
- package/dist/esm/types/logger/main/index.d.ts +3 -0
- package/dist/esm/types/logger/main/loggerBench.d.ts +24 -0
- package/dist/esm/types/logger/main/loggerBenchRecorder.d.ts +1 -0
- package/dist/esm/types/logger/main/loggerModes.d.ts +6 -0
- package/dist/esm/types/types/index.d.ts +1 -1
- package/dist/types/imports/functions.d.ts +1 -1
- package/dist/types/imports/index.d.ts +1 -1
- package/dist/types/imports/utils/index.d.ts +2 -2
- package/dist/types/index.d.ts +4 -4
- package/dist/types/logger/index.d.ts +1 -1
- package/dist/types/logger/logit/blocker.d.ts +4 -0
- package/dist/types/logger/logit/index.d.ts +1 -0
- package/dist/types/logger/logit/logger.d.ts +3 -0
- package/dist/types/logger/main/index.d.ts +3 -0
- package/dist/types/logger/main/loggerBench.d.ts +24 -0
- package/dist/types/logger/main/loggerBenchRecorder.d.ts +1 -0
- package/dist/types/logger/main/loggerModes.d.ts +6 -0
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,145 @@ var require$$1$1 = require('string_decoder');
|
|
|
13
13
|
var require$$0$6 = require('http');
|
|
14
14
|
var require$$1$2 = require('https');
|
|
15
15
|
|
|
16
|
+
if (typeof process === "undefined") {
|
|
17
|
+
throw new Error("@putkoff/abstract-env is Node-only");
|
|
18
|
+
}
|
|
19
|
+
/* ========================================================================== */
|
|
20
|
+
/* Utilities */
|
|
21
|
+
/* ========================================================================== */
|
|
22
|
+
function splitEq(line) {
|
|
23
|
+
const idx = line.indexOf("=");
|
|
24
|
+
if (idx === -1)
|
|
25
|
+
return [line.trim(), null];
|
|
26
|
+
const key = line.slice(0, idx).trim();
|
|
27
|
+
const value = line.slice(idx + 1).trim().replace(/^['"]|['"]$/g, "");
|
|
28
|
+
return [key, value];
|
|
29
|
+
}
|
|
30
|
+
/* ========================================================================== */
|
|
31
|
+
/* AbstractEnv */
|
|
32
|
+
/* ========================================================================== */
|
|
33
|
+
class AbstractEnv {
|
|
34
|
+
key;
|
|
35
|
+
fileName;
|
|
36
|
+
path;
|
|
37
|
+
deepScan;
|
|
38
|
+
currentFolder;
|
|
39
|
+
homeFolder;
|
|
40
|
+
envyAll;
|
|
41
|
+
directories = [];
|
|
42
|
+
envValue = null;
|
|
43
|
+
envPath = null;
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
this.key = options.key ?? "MY_PASSWORD";
|
|
46
|
+
this.fileName = options.fileName ?? ".env";
|
|
47
|
+
this.path = options.startPath ?? process.cwd();
|
|
48
|
+
this.deepScan = options.deepScan ?? false;
|
|
49
|
+
this.currentFolder = process.cwd();
|
|
50
|
+
this.homeFolder = require$$0$1.homedir();
|
|
51
|
+
this.envyAll = path.join(this.homeFolder, ".envy_all");
|
|
52
|
+
this.initialize();
|
|
53
|
+
}
|
|
54
|
+
initialize() {
|
|
55
|
+
if (fs.existsSync(this.path) && fs.statSync(this.path).isFile()) {
|
|
56
|
+
this.fileName = path.basename(this.path);
|
|
57
|
+
this.path = path.dirname(this.path);
|
|
58
|
+
}
|
|
59
|
+
this.directories = this.getDirectories();
|
|
60
|
+
this.envValue = this.findAndReadEnv();
|
|
61
|
+
}
|
|
62
|
+
getDirectories() {
|
|
63
|
+
const dirs = [
|
|
64
|
+
this.path,
|
|
65
|
+
this.currentFolder,
|
|
66
|
+
this.homeFolder,
|
|
67
|
+
this.envyAll,
|
|
68
|
+
];
|
|
69
|
+
return [...new Set(dirs.filter(d => fs.existsSync(d) && fs.statSync(d).isDirectory()))];
|
|
70
|
+
}
|
|
71
|
+
findAndReadEnv() {
|
|
72
|
+
for (const dir of this.directories) {
|
|
73
|
+
const envPath = path.join(dir, this.fileName);
|
|
74
|
+
if (!fs.existsSync(envPath))
|
|
75
|
+
continue;
|
|
76
|
+
this.envPath = envPath;
|
|
77
|
+
const value = this.searchForKey(envPath);
|
|
78
|
+
if (value !== null)
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
searchForKey(filePath) {
|
|
84
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
85
|
+
const lines = content.split(/\r?\n/);
|
|
86
|
+
let bestMatch = null;
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const [lineKey, lineValue] = splitEq(line);
|
|
89
|
+
if (!lineValue)
|
|
90
|
+
continue;
|
|
91
|
+
if (lineKey === this.key)
|
|
92
|
+
return lineValue;
|
|
93
|
+
if (this.deepScan) {
|
|
94
|
+
const score = this.fuzzyScore(this.key, lineKey);
|
|
95
|
+
if (score >= 0.5 && (!bestMatch || score > bestMatch.score)) {
|
|
96
|
+
bestMatch = { value: lineValue, score };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return bestMatch?.value ?? null;
|
|
101
|
+
}
|
|
102
|
+
fuzzyScore(target, candidate) {
|
|
103
|
+
let matched = 0;
|
|
104
|
+
for (const part of target.split("_")) {
|
|
105
|
+
if (candidate.includes(part))
|
|
106
|
+
matched += part.length;
|
|
107
|
+
}
|
|
108
|
+
return matched / target.length;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Retrieve environment variable value by searching .env files.
|
|
114
|
+
*/
|
|
115
|
+
function getEnvValue(options = {}) {
|
|
116
|
+
const env = new AbstractEnv(options);
|
|
117
|
+
return env.envValue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function parseList$1(key) {
|
|
121
|
+
const v = getEnvValue({ key });
|
|
122
|
+
return v ? v.split(",").map(s => s.trim()).filter(Boolean) : [];
|
|
123
|
+
}
|
|
124
|
+
function getLogConfig() {
|
|
125
|
+
return {
|
|
126
|
+
condensed: getEnvValue({ key: "LOG_CONDENSED" }) !== "false",
|
|
127
|
+
expandOnDebug: getEnvValue({ key: "LOG_EXPAND_DEBUG" }) !== "false",
|
|
128
|
+
showDetails: getEnvValue({ key: "LOG_SHOW_DETAILS" }) !== "false",
|
|
129
|
+
showOnly: getEnvValue({ key: "LOG_SHOW_ONLY" }) === "true",
|
|
130
|
+
showOnlyFunctions: parseList$1("LOG_SHOW_ONLY_FUNCTIONS"),
|
|
131
|
+
showOnlyActivities: parseList$1("LOG_SHOW_ONLY_ACTIVITIES"),
|
|
132
|
+
showOnlyTypes: parseList$1("LOG_SHOW_ONLY_TYPES"),
|
|
133
|
+
maxDetailsLength: Number(getEnvValue({ key: "LOG_DETAILS_MAX" }) ?? 500),
|
|
134
|
+
sampleRate: Number(getEnvValue({ key: "LOG_SAMPLE_RATE" }) ?? 1),
|
|
135
|
+
prettyDetails: getEnvValue({ key: "LOG_PRETTY_DETAILS" }) === "true",
|
|
136
|
+
activityBlocklist: parseList$1("LOG_ACTIVITY_BLOCKLIST"),
|
|
137
|
+
logTypeBlocklist: parseList$1("LOG_TYPE_BLOCKLIST"),
|
|
138
|
+
showDetailslist: parseList$1("LOG_DETAILS_ALLOWLIST"),
|
|
139
|
+
functionAllowlist: parseList$1("LOG_FUNCTION_ALLOWLIST"),
|
|
140
|
+
functionBlocklist: parseList$1("LOG_FUNCTION_BLOCKLIST"),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function debugLogConfig() {
|
|
144
|
+
if (getEnvValue({ key: "LOG_DEBUG_CONFIG" }) === "true") {
|
|
145
|
+
console.log("LOG CONFIG ENV:", {
|
|
146
|
+
LOG_SHOW_DETAILS: getEnvValue({ key: "LOG_SHOW_DETAILS" }),
|
|
147
|
+
LOG_DETAILS_ALLOWLIST: getEnvValue({ key: "LOG_DETAILS_ALLOWLIST" }),
|
|
148
|
+
LOG_PRETTY_DETAILS: getEnvValue({ key: "LOG_PRETTY_DETAILS" }),
|
|
149
|
+
LOG_CONDENSED: getEnvValue({ key: "LOG_CONDENSED" }),
|
|
150
|
+
LOG_EXPAND_DEBUG: getEnvValue({ key: "LOG_EXPAND_DEBUG" }),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
16
155
|
/* ------------------------------------------------------------------ */
|
|
17
156
|
/* Stack inspection */
|
|
18
157
|
/* ------------------------------------------------------------------ */
|
|
@@ -42,7 +181,7 @@ function resolveValue(...values) {
|
|
|
42
181
|
}
|
|
43
182
|
return sawInput ? "unknown" : "unknown";
|
|
44
183
|
}
|
|
45
|
-
function parseList
|
|
184
|
+
function parseList(value) {
|
|
46
185
|
return value
|
|
47
186
|
? value.split(",").map(s => s.trim()).filter(Boolean)
|
|
48
187
|
: [];
|
|
@@ -184,145 +323,6 @@ const COLS = {
|
|
|
184
323
|
file: 16,
|
|
185
324
|
};
|
|
186
325
|
|
|
187
|
-
if (typeof process === "undefined") {
|
|
188
|
-
throw new Error("@putkoff/abstract-env is Node-only");
|
|
189
|
-
}
|
|
190
|
-
/* ========================================================================== */
|
|
191
|
-
/* Utilities */
|
|
192
|
-
/* ========================================================================== */
|
|
193
|
-
function splitEq(line) {
|
|
194
|
-
const idx = line.indexOf("=");
|
|
195
|
-
if (idx === -1)
|
|
196
|
-
return [line.trim(), null];
|
|
197
|
-
const key = line.slice(0, idx).trim();
|
|
198
|
-
const value = line.slice(idx + 1).trim().replace(/^['"]|['"]$/g, "");
|
|
199
|
-
return [key, value];
|
|
200
|
-
}
|
|
201
|
-
/* ========================================================================== */
|
|
202
|
-
/* AbstractEnv */
|
|
203
|
-
/* ========================================================================== */
|
|
204
|
-
class AbstractEnv {
|
|
205
|
-
key;
|
|
206
|
-
fileName;
|
|
207
|
-
path;
|
|
208
|
-
deepScan;
|
|
209
|
-
currentFolder;
|
|
210
|
-
homeFolder;
|
|
211
|
-
envyAll;
|
|
212
|
-
directories = [];
|
|
213
|
-
envValue = null;
|
|
214
|
-
envPath = null;
|
|
215
|
-
constructor(options = {}) {
|
|
216
|
-
this.key = options.key ?? "MY_PASSWORD";
|
|
217
|
-
this.fileName = options.fileName ?? ".env";
|
|
218
|
-
this.path = options.startPath ?? process.cwd();
|
|
219
|
-
this.deepScan = options.deepScan ?? false;
|
|
220
|
-
this.currentFolder = process.cwd();
|
|
221
|
-
this.homeFolder = require$$0$1.homedir();
|
|
222
|
-
this.envyAll = path.join(this.homeFolder, ".envy_all");
|
|
223
|
-
this.initialize();
|
|
224
|
-
}
|
|
225
|
-
initialize() {
|
|
226
|
-
if (fs.existsSync(this.path) && fs.statSync(this.path).isFile()) {
|
|
227
|
-
this.fileName = path.basename(this.path);
|
|
228
|
-
this.path = path.dirname(this.path);
|
|
229
|
-
}
|
|
230
|
-
this.directories = this.getDirectories();
|
|
231
|
-
this.envValue = this.findAndReadEnv();
|
|
232
|
-
}
|
|
233
|
-
getDirectories() {
|
|
234
|
-
const dirs = [
|
|
235
|
-
this.path,
|
|
236
|
-
this.currentFolder,
|
|
237
|
-
this.homeFolder,
|
|
238
|
-
this.envyAll,
|
|
239
|
-
];
|
|
240
|
-
return [...new Set(dirs.filter(d => fs.existsSync(d) && fs.statSync(d).isDirectory()))];
|
|
241
|
-
}
|
|
242
|
-
findAndReadEnv() {
|
|
243
|
-
for (const dir of this.directories) {
|
|
244
|
-
const envPath = path.join(dir, this.fileName);
|
|
245
|
-
if (!fs.existsSync(envPath))
|
|
246
|
-
continue;
|
|
247
|
-
this.envPath = envPath;
|
|
248
|
-
const value = this.searchForKey(envPath);
|
|
249
|
-
if (value !== null)
|
|
250
|
-
return value;
|
|
251
|
-
}
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
searchForKey(filePath) {
|
|
255
|
-
const content = fs.readFileSync(filePath, "utf8");
|
|
256
|
-
const lines = content.split(/\r?\n/);
|
|
257
|
-
let bestMatch = null;
|
|
258
|
-
for (const line of lines) {
|
|
259
|
-
const [lineKey, lineValue] = splitEq(line);
|
|
260
|
-
if (!lineValue)
|
|
261
|
-
continue;
|
|
262
|
-
if (lineKey === this.key)
|
|
263
|
-
return lineValue;
|
|
264
|
-
if (this.deepScan) {
|
|
265
|
-
const score = this.fuzzyScore(this.key, lineKey);
|
|
266
|
-
if (score >= 0.5 && (!bestMatch || score > bestMatch.score)) {
|
|
267
|
-
bestMatch = { value: lineValue, score };
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return bestMatch?.value ?? null;
|
|
272
|
-
}
|
|
273
|
-
fuzzyScore(target, candidate) {
|
|
274
|
-
let matched = 0;
|
|
275
|
-
for (const part of target.split("_")) {
|
|
276
|
-
if (candidate.includes(part))
|
|
277
|
-
matched += part.length;
|
|
278
|
-
}
|
|
279
|
-
return matched / target.length;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Retrieve environment variable value by searching .env files.
|
|
285
|
-
*/
|
|
286
|
-
function getEnvValue(options = {}) {
|
|
287
|
-
const env = new AbstractEnv(options);
|
|
288
|
-
return env.envValue;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function parseList(key) {
|
|
292
|
-
const v = getEnvValue({ key });
|
|
293
|
-
return v ? v.split(",").map(s => s.trim()).filter(Boolean) : [];
|
|
294
|
-
}
|
|
295
|
-
function getLogConfig() {
|
|
296
|
-
return {
|
|
297
|
-
condensed: getEnvValue({ key: "LOG_CONDENSED" }) !== "false",
|
|
298
|
-
expandOnDebug: getEnvValue({ key: "LOG_EXPAND_DEBUG" }) !== "false",
|
|
299
|
-
showDetails: getEnvValue({ key: "LOG_SHOW_DETAILS" }) !== "false",
|
|
300
|
-
showOnly: getEnvValue({ key: "LOG_SHOW_ONLY" }) === "true",
|
|
301
|
-
showOnlyFunctions: parseList("LOG_SHOW_ONLY_FUNCTIONS"),
|
|
302
|
-
showOnlyActivities: parseList("LOG_SHOW_ONLY_ACTIVITIES"),
|
|
303
|
-
showOnlyTypes: parseList("LOG_SHOW_ONLY_TYPES"),
|
|
304
|
-
maxDetailsLength: Number(getEnvValue({ key: "LOG_DETAILS_MAX" }) ?? 500),
|
|
305
|
-
sampleRate: Number(getEnvValue({ key: "LOG_SAMPLE_RATE" }) ?? 1),
|
|
306
|
-
prettyDetails: getEnvValue({ key: "LOG_PRETTY_DETAILS" }) === "true",
|
|
307
|
-
activityBlocklist: parseList("LOG_ACTIVITY_BLOCKLIST"),
|
|
308
|
-
logTypeBlocklist: parseList("LOG_TYPE_BLOCKLIST"),
|
|
309
|
-
showDetailslist: parseList("LOG_DETAILS_ALLOWLIST"),
|
|
310
|
-
functionAllowlist: parseList("LOG_FUNCTION_ALLOWLIST"),
|
|
311
|
-
functionBlocklist: parseList("LOG_FUNCTION_BLOCKLIST"),
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function debugLogConfig() {
|
|
315
|
-
if (getEnvValue({ key: "LOG_DEBUG_CONFIG" }) === "true") {
|
|
316
|
-
console.log("LOG CONFIG ENV:", {
|
|
317
|
-
LOG_SHOW_DETAILS: getEnvValue({ key: "LOG_SHOW_DETAILS" }),
|
|
318
|
-
LOG_DETAILS_ALLOWLIST: getEnvValue({ key: "LOG_DETAILS_ALLOWLIST" }),
|
|
319
|
-
LOG_PRETTY_DETAILS: getEnvValue({ key: "LOG_PRETTY_DETAILS" }),
|
|
320
|
-
LOG_CONDENSED: getEnvValue({ key: "LOG_CONDENSED" }),
|
|
321
|
-
LOG_EXPAND_DEBUG: getEnvValue({ key: "LOG_EXPAND_DEBUG" }),
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
326
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
327
327
|
|
|
328
328
|
function getAugmentedNamespace(n) {
|
|
@@ -14864,6 +14864,14 @@ function formatLogLine({ emoji, timestamp, functionName, message, details, file,
|
|
|
14864
14864
|
return line;
|
|
14865
14865
|
}
|
|
14866
14866
|
|
|
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
|
+
|
|
14867
14875
|
const seen = new Map();
|
|
14868
14876
|
function hash(str) {
|
|
14869
14877
|
let h = 0;
|
|
@@ -14931,7 +14939,7 @@ function shouldLog(opts, caller) {
|
|
|
14931
14939
|
return true;
|
|
14932
14940
|
}
|
|
14933
14941
|
|
|
14934
|
-
function
|
|
14942
|
+
function logit(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
|
|
14935
14943
|
/* -------------------------------------------------- */
|
|
14936
14944
|
/* Normalize inputs */
|
|
14937
14945
|
/* -------------------------------------------------- */
|
|
@@ -14949,7 +14957,7 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14949
14957
|
/* -------------------------------------------------- */
|
|
14950
14958
|
/* Caller info */
|
|
14951
14959
|
/* -------------------------------------------------- */
|
|
14952
|
-
const caller = getCallerInfo(
|
|
14960
|
+
const caller = getCallerInfo(logit);
|
|
14953
14961
|
/* -------------------------------------------------- */
|
|
14954
14962
|
/* 🔒 Single source of truth for logType */
|
|
14955
14963
|
/* -------------------------------------------------- */
|
|
@@ -14999,25 +15007,84 @@ function getLogString(messageOrOptions, logType = null, details = null, function
|
|
|
14999
15007
|
}), finalLogType, resolvedLoggerInput);
|
|
15000
15008
|
}
|
|
15001
15009
|
|
|
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
|
+
/* Unified logging entry point */
|
|
15036
|
+
/* ---------------------------------- */
|
|
15037
|
+
function logEvent(props) {
|
|
15038
|
+
stats.calls++;
|
|
15039
|
+
// 🔥 OFF = absolute fastest
|
|
15040
|
+
if (mode === LogMode.OFF)
|
|
15041
|
+
return;
|
|
15042
|
+
const type = typeof props?.logType === "string" ? props.logType : "info";
|
|
15043
|
+
inc(stats.byMode, mode);
|
|
15044
|
+
inc(stats.byType, type);
|
|
15045
|
+
inc(stats.byFunction, props?.function_name);
|
|
15046
|
+
// ⚡ COUNT = no timers, no I/O
|
|
15047
|
+
if (mode === LogMode.COUNT)
|
|
15048
|
+
return;
|
|
15049
|
+
const start = process.hrtime.bigint();
|
|
15050
|
+
if (mode === LogMode.FULL) {
|
|
15051
|
+
logit(props);
|
|
15052
|
+
}
|
|
15053
|
+
else if (mode === LogMode.CONSOLE) {
|
|
15054
|
+
console.log(props);
|
|
15055
|
+
}
|
|
15056
|
+
const elapsed = process.hrtime.bigint() - start;
|
|
15057
|
+
stats.totalNs += elapsed;
|
|
15058
|
+
recordLatency(elapsed);
|
|
15059
|
+
}
|
|
15060
|
+
|
|
15061
|
+
const LOG_DIR = process.env.LOG_BENCH_DIR ??
|
|
15062
|
+
path.resolve(process.cwd(), "log-bench");
|
|
15063
|
+
path.join(LOG_DIR, "bench.ndjson");
|
|
15064
|
+
fs.mkdirSync(LOG_DIR, { recursive: true });
|
|
15065
|
+
|
|
15002
15066
|
exports.COLS = COLS;
|
|
15003
15067
|
exports.IS_BROWSER = IS_BROWSER;
|
|
15004
15068
|
exports.IS_NODE = IS_NODE;
|
|
15005
15069
|
exports.activityEmojiMap = activityEmojiMap;
|
|
15070
|
+
exports.createLogger = winston.createLogger;
|
|
15006
15071
|
exports.debugLogConfig = debugLogConfig;
|
|
15007
15072
|
exports.extractFile = extractFile;
|
|
15073
|
+
exports.format = winston.format;
|
|
15008
15074
|
exports.formatLogLine = formatLogLine;
|
|
15009
15075
|
exports.getCallerInfo = getCallerInfo;
|
|
15010
15076
|
exports.getFinalLine = getFinalLine;
|
|
15011
15077
|
exports.getLogConfig = getLogConfig;
|
|
15012
|
-
exports.getLogString =
|
|
15078
|
+
exports.getLogString = logEvent;
|
|
15013
15079
|
exports.getNodeLogger = getNodeLogger;
|
|
15014
15080
|
exports.logger = logger;
|
|
15015
15081
|
exports.padLeft = padLeft;
|
|
15016
15082
|
exports.padRight = padRight;
|
|
15017
|
-
exports.parseList = parseList
|
|
15083
|
+
exports.parseList = parseList;
|
|
15018
15084
|
exports.resolveLogger = resolveLogger;
|
|
15019
15085
|
exports.resolveValue = resolveValue;
|
|
15020
15086
|
exports.serializeDetails = serializeDetails;
|
|
15021
15087
|
exports.shouldCondense = shouldCondense;
|
|
15022
15088
|
exports.shouldShowDetails = shouldShowDetails;
|
|
15089
|
+
exports.transports = winston.transports;
|
|
15023
15090
|
//# sourceMappingURL=index.js.map
|