@guren/server 2.10.0 → 2.10.1
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/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
- package/dist/Hash-CzrwKeDp.js +133 -0
- package/dist/HttpException-BkS3euNG.js +161 -0
- package/dist/Job-BVT813DO.js +441 -0
- package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
- package/dist/MessageSigner-Bd25ZJAV.js +93 -0
- package/dist/Random-DbIJ22KQ.js +191 -0
- package/dist/address-D0Iq-XIH.js +20 -0
- package/dist/auth/index.js +2 -122
- package/dist/auth-C7sVmYgc.js +1954 -0
- package/dist/authorization/index.js +2 -38
- package/dist/authorization-Dbcuc5ZK.js +610 -0
- package/dist/broadcasting/index.js +2 -26
- package/dist/broadcasting-Dw-FhyjN.js +1055 -0
- package/dist/cache/index.js +2 -17
- package/dist/cache/types.d.ts +4 -4
- package/dist/cache-BYnZf2FR.js +812 -0
- package/dist/client-Dd7vLcqp.js +27 -0
- package/dist/console/Output.d.ts +18 -18
- package/dist/encryption/index.js +5 -96
- package/dist/encryption-fOWQaKqX.js +250 -0
- package/dist/endpoint-D-20PiHY.js +46 -0
- package/dist/endpoint-D6GIqOpe.js +31 -0
- package/dist/errors-quJOkkCn.js +81 -0
- package/dist/events/index.js +2 -28
- package/dist/events-aIH_bWRx.js +410 -0
- package/dist/health/index.js +2 -24
- package/dist/health-VWdWXRwh.js +345 -0
- package/dist/hot-disposables-WsTX2ySN.js +281 -0
- package/dist/hot-reload/testing.d.ts +1 -1
- package/dist/i18n/index.js +2 -30
- package/dist/i18n-mcWi7LCd.js +617 -0
- package/dist/index.js +7495 -7276
- package/dist/lambda/index.js +114 -71
- package/dist/logging/index.js +2 -24
- package/dist/logging-CPaRMuPP.js +518 -0
- package/dist/loopback-guard-D0Kc7-xc.js +224 -0
- package/dist/mail/index.js +2 -27
- package/dist/mail-DfEfSQEr.js +699 -0
- package/dist/mcp/index.js +2 -10
- package/dist/notifications/index.js +2 -33
- package/dist/notifications-BGqmUNZ8.js +759 -0
- package/dist/queue/index.js +3 -42
- package/dist/queue-CXrRK85G.js +948 -0
- package/dist/redis/index.js +672 -642
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime/index.js +472 -616
- package/dist/scheduling/index.js +2 -29
- package/dist/scheduling-CPiEdtQd.js +839 -0
- package/dist/storage/index.js +2 -15
- package/dist/storage-tWHMv2H_.js +841 -0
- package/dist/support/expiry.js +69 -12
- package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
- package/dist/vite/index.js +118 -181
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite-dev-server-CpCUqmiC.js +131 -0
- package/package.json +6 -5
- package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
- package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
- package/dist/chunk-2SC566CD.js +0 -376
- package/dist/chunk-2V3YID4H.js +0 -20
- package/dist/chunk-3KV5X2FL.js +0 -31
- package/dist/chunk-63SKW5PS.js +0 -457
- package/dist/chunk-6J6B5KOB.js +0 -425
- package/dist/chunk-A5JJ7XTH.js +0 -24
- package/dist/chunk-AZOYI43J.js +0 -18
- package/dist/chunk-B5E5VBDI.js +0 -115
- package/dist/chunk-DAQKYKLH.js +0 -182
- package/dist/chunk-DRNPVBAA.js +0 -1002
- package/dist/chunk-EI5GYMAT.js +0 -853
- package/dist/chunk-H3B23O6T.js +0 -271
- package/dist/chunk-HPET6XY5.js +0 -853
- package/dist/chunk-HR2KZ3WL.js +0 -616
- package/dist/chunk-IOTWFHZU.js +0 -558
- package/dist/chunk-K6CUBJX6.js +0 -642
- package/dist/chunk-KTNJG7R7.js +0 -911
- package/dist/chunk-LAJQCSSF.js +0 -355
- package/dist/chunk-LHR6OHI7.js +0 -189
- package/dist/chunk-N7PLD7MB.js +0 -729
- package/dist/chunk-Q2P6YLRR.js +0 -24
- package/dist/chunk-QQKTH5KX.js +0 -114
- package/dist/chunk-SFQP6O52.js +0 -126
- package/dist/chunk-SQR7277M.js +0 -911
- package/dist/chunk-T2FFUU6J.js +0 -484
- package/dist/chunk-TVV5YNEC.js +0 -1842
- package/dist/chunk-UY3AZSYL.js +0 -14
- package/dist/chunk-V4DNC2ER.js +0 -114
- package/dist/chunk-VSA3QY5Q.js +0 -274
- package/dist/chunk-YSOJKAAU.js +0 -427
- package/dist/errors-PUNHAFL2.js +0 -34
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import * as path$1 from "node:path";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
//#region src/logging/types.ts
|
|
4
|
+
/**
|
|
5
|
+
* Log level priority (lower = more severe).
|
|
6
|
+
*/
|
|
7
|
+
const LOG_LEVEL_PRIORITY = {
|
|
8
|
+
emergency: 0,
|
|
9
|
+
alert: 1,
|
|
10
|
+
critical: 2,
|
|
11
|
+
error: 3,
|
|
12
|
+
warning: 4,
|
|
13
|
+
notice: 5,
|
|
14
|
+
info: 6,
|
|
15
|
+
debug: 7
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/logging/Logger.ts
|
|
19
|
+
const DEFAULT_FILTER_KEYS = [
|
|
20
|
+
"password",
|
|
21
|
+
"password_confirmation",
|
|
22
|
+
"token",
|
|
23
|
+
"secret",
|
|
24
|
+
"credit_card",
|
|
25
|
+
"creditCard",
|
|
26
|
+
"card_number",
|
|
27
|
+
"cardNumber",
|
|
28
|
+
"cvv",
|
|
29
|
+
"ssn",
|
|
30
|
+
"authorization"
|
|
31
|
+
];
|
|
32
|
+
/**
|
|
33
|
+
* Recursively replace values of sensitive keys in a log context object.
|
|
34
|
+
*/
|
|
35
|
+
function filterSensitiveData(data, filterKeys, replacement = "[FILTERED]") {
|
|
36
|
+
if (filterKeys.length === 0) return data;
|
|
37
|
+
return filterObject(data, new Set(filterKeys.map((k) => k.toLowerCase())), replacement);
|
|
38
|
+
}
|
|
39
|
+
function filterObject(obj, keySet, replacement) {
|
|
40
|
+
const result = {};
|
|
41
|
+
for (const [key, value] of Object.entries(obj)) if (keySet.has(key.toLowerCase())) result[key] = replacement;
|
|
42
|
+
else if (value !== null && typeof value === "object" && !Array.isArray(value)) result[key] = filterObject(value, keySet, replacement);
|
|
43
|
+
else if (Array.isArray(value)) result[key] = value.map((item) => item !== null && typeof item === "object" && !Array.isArray(item) ? filterObject(item, keySet, replacement) : item);
|
|
44
|
+
else result[key] = value;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Logger instance for writing log entries.
|
|
49
|
+
*/
|
|
50
|
+
var Logger = class Logger {
|
|
51
|
+
channels;
|
|
52
|
+
baseContext;
|
|
53
|
+
filterKeys;
|
|
54
|
+
replacement;
|
|
55
|
+
constructor(channels, context = {}, options = {}) {
|
|
56
|
+
this.channels = channels;
|
|
57
|
+
this.baseContext = context;
|
|
58
|
+
this.filterKeys = options.filterKeys ?? DEFAULT_FILTER_KEYS;
|
|
59
|
+
this.replacement = options.replacement ?? "[FILTERED]";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Log at emergency level (system is unusable).
|
|
63
|
+
*/
|
|
64
|
+
emergency(message, context = {}) {
|
|
65
|
+
this.log("emergency", message, context);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Log at alert level (action must be taken immediately).
|
|
69
|
+
*/
|
|
70
|
+
alert(message, context = {}) {
|
|
71
|
+
this.log("alert", message, context);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Log at critical level (critical conditions).
|
|
75
|
+
*/
|
|
76
|
+
critical(message, context = {}) {
|
|
77
|
+
this.log("critical", message, context);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Log at error level (error conditions).
|
|
81
|
+
*/
|
|
82
|
+
error(message, context = {}) {
|
|
83
|
+
this.log("error", message, context);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Log at warning level (warning conditions).
|
|
87
|
+
*/
|
|
88
|
+
warning(message, context = {}) {
|
|
89
|
+
this.log("warning", message, context);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Alias for warning().
|
|
93
|
+
*/
|
|
94
|
+
warn(message, context = {}) {
|
|
95
|
+
this.warning(message, context);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Log at notice level (normal but significant conditions).
|
|
99
|
+
*/
|
|
100
|
+
notice(message, context = {}) {
|
|
101
|
+
this.log("notice", message, context);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Log at info level (informational messages).
|
|
105
|
+
*/
|
|
106
|
+
info(message, context = {}) {
|
|
107
|
+
this.log("info", message, context);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Log at debug level (debug-level messages).
|
|
111
|
+
*/
|
|
112
|
+
debug(message, context = {}) {
|
|
113
|
+
this.log("debug", message, context);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Log a message at the specified level.
|
|
117
|
+
*/
|
|
118
|
+
log(level, message, context = {}) {
|
|
119
|
+
const merged = {
|
|
120
|
+
...this.baseContext,
|
|
121
|
+
...context
|
|
122
|
+
};
|
|
123
|
+
const entry = {
|
|
124
|
+
level,
|
|
125
|
+
message,
|
|
126
|
+
context: this.filterKeys.length > 0 ? filterSensitiveData(merged, this.filterKeys, this.replacement) : merged,
|
|
127
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
128
|
+
};
|
|
129
|
+
for (const channel of this.channels) try {
|
|
130
|
+
channel.log(entry);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error("Logging error:", error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a new logger with additional context.
|
|
137
|
+
*/
|
|
138
|
+
withContext(context) {
|
|
139
|
+
return new Logger(this.channels, {
|
|
140
|
+
...this.baseContext,
|
|
141
|
+
...context
|
|
142
|
+
}, {
|
|
143
|
+
filterKeys: this.filterKeys,
|
|
144
|
+
replacement: this.replacement
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create a child logger with additional context (alias for withContext).
|
|
149
|
+
*/
|
|
150
|
+
child(context) {
|
|
151
|
+
return this.withContext(context);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Close all channels.
|
|
155
|
+
*/
|
|
156
|
+
async close() {
|
|
157
|
+
for (const channel of this.channels) if (channel.close) await channel.close();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/logging/channels/ConsoleChannel.ts
|
|
162
|
+
/**
|
|
163
|
+
* ANSI color codes for log levels.
|
|
164
|
+
*/
|
|
165
|
+
const LEVEL_COLORS = {
|
|
166
|
+
emergency: "\x1B[41m\x1B[37m",
|
|
167
|
+
alert: "\x1B[41m\x1B[37m",
|
|
168
|
+
critical: "\x1B[31m",
|
|
169
|
+
error: "\x1B[31m",
|
|
170
|
+
warning: "\x1B[33m",
|
|
171
|
+
notice: "\x1B[36m",
|
|
172
|
+
info: "\x1B[32m",
|
|
173
|
+
debug: "\x1B[90m"
|
|
174
|
+
};
|
|
175
|
+
const RESET = "\x1B[0m";
|
|
176
|
+
/**
|
|
177
|
+
* Console log channel.
|
|
178
|
+
*/
|
|
179
|
+
var ConsoleChannel = class {
|
|
180
|
+
config;
|
|
181
|
+
minLevel;
|
|
182
|
+
constructor(config) {
|
|
183
|
+
this.config = {
|
|
184
|
+
colors: true,
|
|
185
|
+
timestamps: true,
|
|
186
|
+
format: "text",
|
|
187
|
+
...config
|
|
188
|
+
};
|
|
189
|
+
this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
|
|
190
|
+
}
|
|
191
|
+
log(entry) {
|
|
192
|
+
const entryLevel = LOG_LEVEL_PRIORITY[entry.level];
|
|
193
|
+
if (entryLevel > this.minLevel) return;
|
|
194
|
+
const output = this.format(entry);
|
|
195
|
+
if (entryLevel <= LOG_LEVEL_PRIORITY.error) console.error(output);
|
|
196
|
+
else if (entryLevel <= LOG_LEVEL_PRIORITY.warning) console.warn(output);
|
|
197
|
+
else if (entryLevel <= LOG_LEVEL_PRIORITY.info) console.info(output);
|
|
198
|
+
else console.log(output);
|
|
199
|
+
}
|
|
200
|
+
format(entry) {
|
|
201
|
+
if (this.config.format === "json") return JSON.stringify({
|
|
202
|
+
timestamp: entry.timestamp.toISOString(),
|
|
203
|
+
level: entry.level,
|
|
204
|
+
message: entry.message,
|
|
205
|
+
...entry.context
|
|
206
|
+
});
|
|
207
|
+
const parts = [];
|
|
208
|
+
if (this.config.timestamps) {
|
|
209
|
+
const time = entry.timestamp.toISOString();
|
|
210
|
+
parts.push(this.config.colors ? `\x1b[90m[${time}]\x1b[0m` : `[${time}]`);
|
|
211
|
+
}
|
|
212
|
+
const levelStr = entry.level.toUpperCase().padEnd(9);
|
|
213
|
+
if (this.config.colors) parts.push(`${LEVEL_COLORS[entry.level]}${levelStr}${RESET}`);
|
|
214
|
+
else parts.push(levelStr);
|
|
215
|
+
parts.push(entry.message);
|
|
216
|
+
if (Object.keys(entry.context).length > 0) {
|
|
217
|
+
const contextStr = JSON.stringify(entry.context);
|
|
218
|
+
if (this.config.colors) parts.push(`\x1b[90m${contextStr}${RESET}`);
|
|
219
|
+
else parts.push(contextStr);
|
|
220
|
+
}
|
|
221
|
+
return parts.join(" ");
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/logging/channels/FileChannel.ts
|
|
226
|
+
/**
|
|
227
|
+
* File log channel.
|
|
228
|
+
*/
|
|
229
|
+
var FileChannel = class {
|
|
230
|
+
config;
|
|
231
|
+
minLevel;
|
|
232
|
+
initialized = false;
|
|
233
|
+
constructor(config) {
|
|
234
|
+
this.config = {
|
|
235
|
+
format: "text",
|
|
236
|
+
...config
|
|
237
|
+
};
|
|
238
|
+
this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
|
|
239
|
+
}
|
|
240
|
+
log(entry) {
|
|
241
|
+
if (LOG_LEVEL_PRIORITY[entry.level] > this.minLevel) return;
|
|
242
|
+
const line = this.format(entry) + "\n";
|
|
243
|
+
this.write(line);
|
|
244
|
+
}
|
|
245
|
+
write(data) {
|
|
246
|
+
if (!this.initialized) {
|
|
247
|
+
this.ensureDirectory();
|
|
248
|
+
this.initialized = true;
|
|
249
|
+
}
|
|
250
|
+
fs.appendFileSync(this.config.path, data);
|
|
251
|
+
}
|
|
252
|
+
ensureDirectory() {
|
|
253
|
+
const dir = path$1.dirname(this.config.path);
|
|
254
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
255
|
+
}
|
|
256
|
+
format(entry) {
|
|
257
|
+
if (this.config.format === "json") return JSON.stringify({
|
|
258
|
+
timestamp: entry.timestamp.toISOString(),
|
|
259
|
+
level: entry.level,
|
|
260
|
+
message: entry.message,
|
|
261
|
+
...entry.context
|
|
262
|
+
});
|
|
263
|
+
const timestamp = entry.timestamp.toISOString();
|
|
264
|
+
const level = entry.level.toUpperCase().padEnd(9);
|
|
265
|
+
const context = Object.keys(entry.context).length > 0 ? " " + JSON.stringify(entry.context) : "";
|
|
266
|
+
return `[${timestamp}] ${level} ${entry.message}${context}`;
|
|
267
|
+
}
|
|
268
|
+
close() {}
|
|
269
|
+
};
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/logging/channels/DailyFileChannel.ts
|
|
272
|
+
/**
|
|
273
|
+
* Daily rotating file log channel.
|
|
274
|
+
*/
|
|
275
|
+
var DailyFileChannel = class {
|
|
276
|
+
config;
|
|
277
|
+
minLevel;
|
|
278
|
+
currentDate = null;
|
|
279
|
+
currentFilePath = null;
|
|
280
|
+
constructor(config) {
|
|
281
|
+
this.config = {
|
|
282
|
+
days: 14,
|
|
283
|
+
format: "text",
|
|
284
|
+
...config
|
|
285
|
+
};
|
|
286
|
+
this.minLevel = LOG_LEVEL_PRIORITY[this.config.level ?? "debug"];
|
|
287
|
+
}
|
|
288
|
+
log(entry) {
|
|
289
|
+
if (LOG_LEVEL_PRIORITY[entry.level] > this.minLevel) return;
|
|
290
|
+
const dateStr = this.getDateString(entry.timestamp);
|
|
291
|
+
if (this.currentDate !== dateStr) this.rotate(dateStr);
|
|
292
|
+
const line = this.format(entry) + "\n";
|
|
293
|
+
this.write(line);
|
|
294
|
+
}
|
|
295
|
+
write(data) {
|
|
296
|
+
if (this.currentFilePath) fs.appendFileSync(this.currentFilePath, data);
|
|
297
|
+
}
|
|
298
|
+
rotate(dateStr) {
|
|
299
|
+
this.currentDate = dateStr;
|
|
300
|
+
this.currentFilePath = this.getFilePath(dateStr);
|
|
301
|
+
this.ensureDirectory(this.currentFilePath);
|
|
302
|
+
this.cleanup();
|
|
303
|
+
}
|
|
304
|
+
getFilePath(dateStr) {
|
|
305
|
+
const { dir, name, ext } = path$1.parse(this.config.path);
|
|
306
|
+
return path$1.join(dir, `${name}-${dateStr}${ext}`);
|
|
307
|
+
}
|
|
308
|
+
getDateString(date) {
|
|
309
|
+
return date.toISOString().split("T")[0];
|
|
310
|
+
}
|
|
311
|
+
ensureDirectory(filePath) {
|
|
312
|
+
const dir = path$1.dirname(filePath);
|
|
313
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
314
|
+
}
|
|
315
|
+
cleanup() {
|
|
316
|
+
const { dir, name, ext } = path$1.parse(this.config.path);
|
|
317
|
+
if (!fs.existsSync(dir)) return;
|
|
318
|
+
const files = fs.readdirSync(dir);
|
|
319
|
+
const pattern = new RegExp(`^${name}-(\\d{4}-\\d{2}-\\d{2})${ext.replace(".", "\\.")}$`);
|
|
320
|
+
const cutoff = /* @__PURE__ */ new Date();
|
|
321
|
+
cutoff.setDate(cutoff.getDate() - (this.config.days ?? 14));
|
|
322
|
+
for (const file of files) {
|
|
323
|
+
const match = file.match(pattern);
|
|
324
|
+
if (match) {
|
|
325
|
+
if (new Date(match[1]) < cutoff) fs.unlinkSync(path$1.join(dir, file));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
format(entry) {
|
|
330
|
+
if (this.config.format === "json") return JSON.stringify({
|
|
331
|
+
timestamp: entry.timestamp.toISOString(),
|
|
332
|
+
level: entry.level,
|
|
333
|
+
message: entry.message,
|
|
334
|
+
...entry.context
|
|
335
|
+
});
|
|
336
|
+
const timestamp = entry.timestamp.toISOString();
|
|
337
|
+
const level = entry.level.toUpperCase().padEnd(9);
|
|
338
|
+
const context = Object.keys(entry.context).length > 0 ? " " + JSON.stringify(entry.context) : "";
|
|
339
|
+
return `[${timestamp}] ${level} ${entry.message}${context}`;
|
|
340
|
+
}
|
|
341
|
+
close() {}
|
|
342
|
+
};
|
|
343
|
+
//#endregion
|
|
344
|
+
//#region src/logging/LogManager.ts
|
|
345
|
+
/**
|
|
346
|
+
* Log manager for managing multiple logging channels.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const log = new LogManager({
|
|
351
|
+
* default: 'stack',
|
|
352
|
+
* channels: {
|
|
353
|
+
* console: { driver: 'console', level: 'debug' },
|
|
354
|
+
* file: { driver: 'daily', path: './storage/logs/app.log', days: 14 },
|
|
355
|
+
* stack: { driver: 'stack', channels: ['console', 'file'] },
|
|
356
|
+
* }
|
|
357
|
+
* })
|
|
358
|
+
*
|
|
359
|
+
* log.info('User logged in', { userId: user.id })
|
|
360
|
+
* log.error('Payment failed', { orderId, error: error.message })
|
|
361
|
+
*
|
|
362
|
+
* const requestLog = log.withContext({ requestId: ctx.requestId })
|
|
363
|
+
* requestLog.info('Processing request')
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
var LogManager = class {
|
|
367
|
+
config;
|
|
368
|
+
channelFactories = /* @__PURE__ */ new Map();
|
|
369
|
+
channelInstances = /* @__PURE__ */ new Map();
|
|
370
|
+
loggers = /* @__PURE__ */ new Map();
|
|
371
|
+
loggerOptions;
|
|
372
|
+
constructor(config) {
|
|
373
|
+
this.config = config;
|
|
374
|
+
this.loggerOptions = {
|
|
375
|
+
filterKeys: config.filterKeys,
|
|
376
|
+
replacement: config.filterReplacement
|
|
377
|
+
};
|
|
378
|
+
this.registerDefaultDrivers();
|
|
379
|
+
}
|
|
380
|
+
registerDefaultDrivers() {
|
|
381
|
+
this.registerDriver("console", (config) => {
|
|
382
|
+
return new ConsoleChannel(config);
|
|
383
|
+
});
|
|
384
|
+
this.registerDriver("file", (config) => {
|
|
385
|
+
return new FileChannel(config);
|
|
386
|
+
});
|
|
387
|
+
this.registerDriver("daily", (config) => {
|
|
388
|
+
return new DailyFileChannel(config);
|
|
389
|
+
});
|
|
390
|
+
this.registerDriver("stack", (config) => {
|
|
391
|
+
return this.createStackChannel(config);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
createStackChannel(config) {
|
|
395
|
+
const channels = config.channels.map((name) => this.resolveChannel(name));
|
|
396
|
+
return {
|
|
397
|
+
log: (entry) => {
|
|
398
|
+
for (const channel of channels) channel.log(entry);
|
|
399
|
+
},
|
|
400
|
+
close: async () => {
|
|
401
|
+
for (const channel of channels) if (channel.close) await channel.close();
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Register a custom channel driver.
|
|
407
|
+
*/
|
|
408
|
+
registerDriver(name, factory) {
|
|
409
|
+
this.channelFactories.set(name, factory);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Get a logger for a specific channel.
|
|
413
|
+
*/
|
|
414
|
+
channel(name) {
|
|
415
|
+
const channelName = name ?? this.config.default;
|
|
416
|
+
if (!this.loggers.has(channelName)) {
|
|
417
|
+
const channel = this.resolveChannel(channelName);
|
|
418
|
+
this.loggers.set(channelName, new Logger([channel], {}, this.loggerOptions));
|
|
419
|
+
}
|
|
420
|
+
return this.loggers.get(channelName);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Get a logger that writes to multiple channels.
|
|
424
|
+
*/
|
|
425
|
+
stack(channelNames) {
|
|
426
|
+
const key = `stack:${channelNames.join(",")}`;
|
|
427
|
+
if (!this.loggers.has(key)) {
|
|
428
|
+
const channels = channelNames.map((name) => this.resolveChannel(name));
|
|
429
|
+
this.loggers.set(key, new Logger(channels, {}, this.loggerOptions));
|
|
430
|
+
}
|
|
431
|
+
return this.loggers.get(key);
|
|
432
|
+
}
|
|
433
|
+
resolveChannel(name) {
|
|
434
|
+
if (this.channelInstances.has(name)) return this.channelInstances.get(name);
|
|
435
|
+
const config = this.config.channels[name];
|
|
436
|
+
if (!config) throw new Error(`Log channel [${name}] is not defined`);
|
|
437
|
+
const factory = this.channelFactories.get(config.driver);
|
|
438
|
+
if (!factory) throw new Error(`Log driver [${config.driver}] is not supported`);
|
|
439
|
+
const channel = factory(config);
|
|
440
|
+
this.channelInstances.set(name, channel);
|
|
441
|
+
return channel;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Create a logger with additional context using the default channel.
|
|
445
|
+
*/
|
|
446
|
+
withContext(context) {
|
|
447
|
+
return this.channel().withContext(context);
|
|
448
|
+
}
|
|
449
|
+
emergency(message, context) {
|
|
450
|
+
this.channel().emergency(message, context);
|
|
451
|
+
}
|
|
452
|
+
alert(message, context) {
|
|
453
|
+
this.channel().alert(message, context);
|
|
454
|
+
}
|
|
455
|
+
critical(message, context) {
|
|
456
|
+
this.channel().critical(message, context);
|
|
457
|
+
}
|
|
458
|
+
error(message, context) {
|
|
459
|
+
this.channel().error(message, context);
|
|
460
|
+
}
|
|
461
|
+
warning(message, context) {
|
|
462
|
+
this.channel().warning(message, context);
|
|
463
|
+
}
|
|
464
|
+
warn(message, context) {
|
|
465
|
+
this.channel().warn(message, context);
|
|
466
|
+
}
|
|
467
|
+
notice(message, context) {
|
|
468
|
+
this.channel().notice(message, context);
|
|
469
|
+
}
|
|
470
|
+
info(message, context) {
|
|
471
|
+
this.channel().info(message, context);
|
|
472
|
+
}
|
|
473
|
+
debug(message, context) {
|
|
474
|
+
this.channel().debug(message, context);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Close all channel instances.
|
|
478
|
+
*/
|
|
479
|
+
async close() {
|
|
480
|
+
for (const channel of this.channelInstances.values()) if (channel.close) await channel.close();
|
|
481
|
+
this.channelInstances.clear();
|
|
482
|
+
this.loggers.clear();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Get the default channel name.
|
|
486
|
+
*/
|
|
487
|
+
getDefaultChannel() {
|
|
488
|
+
return this.config.default;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Get available channel names.
|
|
492
|
+
*/
|
|
493
|
+
getChannelNames() {
|
|
494
|
+
return Object.keys(this.config.channels);
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Create a log manager instance.
|
|
499
|
+
*/
|
|
500
|
+
function createLogManager(config) {
|
|
501
|
+
return new LogManager(config);
|
|
502
|
+
}
|
|
503
|
+
let globalLogManager = null;
|
|
504
|
+
/**
|
|
505
|
+
* Set the global log manager instance.
|
|
506
|
+
*/
|
|
507
|
+
function setLogManager(manager) {
|
|
508
|
+
globalLogManager = manager;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Get the global log manager instance.
|
|
512
|
+
*/
|
|
513
|
+
function getLogManager() {
|
|
514
|
+
if (!globalLogManager) throw new Error("Log manager has not been initialized. Call setLogManager() first.");
|
|
515
|
+
return globalLogManager;
|
|
516
|
+
}
|
|
517
|
+
//#endregion
|
|
518
|
+
export { DailyFileChannel as a, Logger as c, setLogManager as i, filterSensitiveData as l, createLogManager as n, FileChannel as o, getLogManager as r, ConsoleChannel as s, LogManager as t, LOG_LEVEL_PRIORITY as u };
|