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