@noxfly/noxus 3.0.0-dev.4 → 3.0.0-dev.5
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/child.js.map +1 -0
- package/dist/child.mjs.map +1 -0
- package/dist/main.js.map +1 -0
- package/dist/main.mjs.map +1 -0
- package/dist/preload.js.map +1 -0
- package/dist/preload.mjs.map +1 -0
- package/dist/renderer.js.map +1 -0
- package/dist/renderer.mjs.map +1 -0
- package/package.json +10 -9
- package/.editorconfig +0 -16
- package/.github/copilot-instructions.md +0 -128
- package/.vscode/settings.json +0 -3
- package/AGENTS.md +0 -5
- package/eslint.config.js +0 -109
- package/scripts/postbuild.js +0 -31
- package/src/DI/app-injector.ts +0 -173
- package/src/DI/injector-explorer.ts +0 -201
- package/src/DI/token.ts +0 -53
- package/src/decorators/controller.decorator.ts +0 -58
- package/src/decorators/guards.decorator.ts +0 -15
- package/src/decorators/injectable.decorator.ts +0 -81
- package/src/decorators/method.decorator.ts +0 -66
- package/src/decorators/middleware.decorator.ts +0 -15
- package/src/index.ts +0 -10
- package/src/internal/app.ts +0 -219
- package/src/internal/bootstrap.ts +0 -141
- package/src/internal/exceptions.ts +0 -57
- package/src/internal/preload-bridge.ts +0 -75
- package/src/internal/renderer-client.ts +0 -374
- package/src/internal/renderer-events.ts +0 -110
- package/src/internal/request.ts +0 -102
- package/src/internal/router.ts +0 -365
- package/src/internal/routes.ts +0 -142
- package/src/internal/socket.ts +0 -75
- package/src/main.ts +0 -26
- package/src/non-electron-process.ts +0 -22
- package/src/preload.ts +0 -10
- package/src/renderer.ts +0 -13
- package/src/utils/forward-ref.ts +0 -31
- package/src/utils/logger.ts +0 -430
- package/src/utils/radix-tree.ts +0 -243
- package/src/utils/types.ts +0 -21
- package/src/window/window-manager.ts +0 -302
- package/tsconfig.json +0 -29
- package/tsup.config.ts +0 -50
package/src/main.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*
|
|
6
|
-
* Entry point for Electron main-process consumers.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export * from './DI/app-injector';
|
|
10
|
-
export * from './DI/token';
|
|
11
|
-
export * from './internal/router';
|
|
12
|
-
export * from './internal/app';
|
|
13
|
-
export * from './internal/bootstrap';
|
|
14
|
-
export * from './internal/exceptions';
|
|
15
|
-
export * from './decorators/middleware.decorator';
|
|
16
|
-
export * from './decorators/guards.decorator';
|
|
17
|
-
export * from './decorators/controller.decorator';
|
|
18
|
-
export * from './decorators/injectable.decorator';
|
|
19
|
-
export * from './decorators/method.decorator';
|
|
20
|
-
export * from './utils/logger';
|
|
21
|
-
export * from './utils/types';
|
|
22
|
-
export * from './utils/forward-ref';
|
|
23
|
-
export * from './internal/request';
|
|
24
|
-
export * from './internal/socket';
|
|
25
|
-
export * from './window/window-manager';
|
|
26
|
-
export * from './internal/routes';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Entry point for nodeJS non-electron process consumers.
|
|
9
|
-
* For instance, if main process creates a child process that
|
|
10
|
-
* wants to use Logger and DI.
|
|
11
|
-
* Child processes must not try to communicate with the renderer
|
|
12
|
-
* process.
|
|
13
|
-
* order of exports here matters and can affect module resolution.
|
|
14
|
-
* Please be cautious when modifying.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
export * from './DI/app-injector';
|
|
18
|
-
export * from './internal/exceptions';
|
|
19
|
-
export * from './decorators/injectable.decorator';
|
|
20
|
-
export * from './utils/logger';
|
|
21
|
-
export * from './utils/types';
|
|
22
|
-
export * from './utils/forward-ref';
|
package/src/preload.ts
DELETED
package/src/renderer.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*
|
|
6
|
-
* Entry point for renderer web consumers (Angular, React, Vue, Vanilla...).
|
|
7
|
-
* No Electron imports — safe to bundle with any web bundler.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
export * from './internal/renderer-client';
|
|
11
|
-
export * from './internal/renderer-events';
|
|
12
|
-
export * from './internal/request';
|
|
13
|
-
export type { HttpMethod, AtomicHttpMethod } from './decorators/method.decorator';
|
package/src/utils/forward-ref.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Type } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A function that returns a type.
|
|
11
|
-
* Used for forward references to types that are not yet defined.
|
|
12
|
-
*/
|
|
13
|
-
export interface ForwardRefFn<T = any> {
|
|
14
|
-
(): Type<T>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A wrapper class for forward referenced types.
|
|
19
|
-
*/
|
|
20
|
-
export class ForwardReference<T = any> {
|
|
21
|
-
constructor(public readonly forwardRefFn: ForwardRefFn<T>) {}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Creates a forward reference to a type.
|
|
26
|
-
* @param fn A function that returns the type.
|
|
27
|
-
* @returns A ForwardReference instance.
|
|
28
|
-
*/
|
|
29
|
-
export function forwardRef<T = any>(fn: ForwardRefFn<T>): ForwardReference<T> {
|
|
30
|
-
return new ForwardReference(fn);
|
|
31
|
-
}
|
package/src/utils/logger.ts
DELETED
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright 2025 NoxFly
|
|
3
|
-
* @license MIT
|
|
4
|
-
* @author NoxFly
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as fs from 'fs';
|
|
8
|
-
import * as path from 'path';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Logger is a utility class for logging messages to the console.
|
|
12
|
-
*/
|
|
13
|
-
export type LogLevel =
|
|
14
|
-
| 'debug'
|
|
15
|
-
| 'comment'
|
|
16
|
-
| 'log'
|
|
17
|
-
| 'info'
|
|
18
|
-
| 'warn'
|
|
19
|
-
| 'error'
|
|
20
|
-
| 'critical'
|
|
21
|
-
;
|
|
22
|
-
|
|
23
|
-
interface FileLogState {
|
|
24
|
-
queue: string[];
|
|
25
|
-
isWriting: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns a formatted timestamp for logging.
|
|
32
|
-
*/
|
|
33
|
-
function getPrettyTimestamp(): string {
|
|
34
|
-
const now = new Date();
|
|
35
|
-
return `${now.getDate().toString().padStart(2, '0')}/${(now.getMonth() + 1).toString().padStart(2, '0')}/${now.getFullYear()}`
|
|
36
|
-
+ ` ${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generates a log prefix for the console output.
|
|
41
|
-
* @param callee - The name of the function or class that is logging the message.
|
|
42
|
-
* @param messageType - The type of message being logged (e.g., 'log', 'info', 'warn', 'error', 'debug').
|
|
43
|
-
* @param color - The color to use for the log message.
|
|
44
|
-
* @returns A formatted string that includes the timestamp, process ID, message type, and callee name.
|
|
45
|
-
*/
|
|
46
|
-
function getLogPrefix(callee: string, messageType: string, color?: string): string {
|
|
47
|
-
const timestamp = getPrettyTimestamp();
|
|
48
|
-
|
|
49
|
-
const spaces = " ".repeat(10 - messageType.length);
|
|
50
|
-
|
|
51
|
-
let colReset = Logger.colors.initial;
|
|
52
|
-
let colCallee = Logger.colors.yellow;
|
|
53
|
-
|
|
54
|
-
if(color === undefined) {
|
|
55
|
-
color = "";
|
|
56
|
-
colReset = "";
|
|
57
|
-
colCallee = "";
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return `${color}[APP] ${process.pid} - ${colReset}`
|
|
61
|
-
+ `${timestamp}${spaces}`
|
|
62
|
-
+ `${color}${messageType.toUpperCase()}${colReset} `
|
|
63
|
-
+ `${colCallee}[${callee}]${colReset}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Formats an object into a string representation for logging.
|
|
68
|
-
* It converts the object to JSON and adds indentation for readability.
|
|
69
|
-
* @param prefix - The prefix to use for the formatted object.
|
|
70
|
-
* @param arg - The object to format.
|
|
71
|
-
* @returns A formatted string representation of the object, with each line prefixed by the specified prefix.
|
|
72
|
-
*/
|
|
73
|
-
function formatObject(prefix: string, arg: object, enableColor: boolean = true): string {
|
|
74
|
-
const json = JSON.stringify(arg, null, 2);
|
|
75
|
-
|
|
76
|
-
let colStart = "";
|
|
77
|
-
let colLine = "";
|
|
78
|
-
let colReset = "";
|
|
79
|
-
|
|
80
|
-
if(enableColor) {
|
|
81
|
-
colStart = Logger.colors.darkGrey;
|
|
82
|
-
colLine = Logger.colors.grey;
|
|
83
|
-
colReset = Logger.colors.initial;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const prefixedJson = json
|
|
87
|
-
.split('\n')
|
|
88
|
-
.map((line, idx) => idx === 0 ? `${colStart}${line}` : `${prefix} ${colLine}${line}`)
|
|
89
|
-
.join('\n') + colReset;
|
|
90
|
-
|
|
91
|
-
return prefixedJson;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Formats the arguments for logging.
|
|
96
|
-
* It colors strings and formats objects with indentation.
|
|
97
|
-
* This function is used to prepare the arguments for console output.
|
|
98
|
-
* @param prefix - The prefix to use for the formatted arguments.
|
|
99
|
-
* @param args - The arguments to format.
|
|
100
|
-
* @param color - The color to use for the formatted arguments.
|
|
101
|
-
* @returns An array of formatted arguments, where strings are colored and objects are formatted with indentation.
|
|
102
|
-
*/
|
|
103
|
-
function formattedArgs(prefix: string, args: any[], color?: string): any[] {
|
|
104
|
-
let colReset = Logger.colors.initial;
|
|
105
|
-
|
|
106
|
-
if(color === undefined) {
|
|
107
|
-
color = "";
|
|
108
|
-
colReset = "";
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return args.map(arg => {
|
|
112
|
-
if(typeof arg === "string") {
|
|
113
|
-
return `${color}${arg}${colReset}`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
else if(typeof arg === "object") {
|
|
117
|
-
return formatObject(prefix, arg, color !== "");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return arg;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Gets the name of the caller function or class from the stack trace.
|
|
126
|
-
* This function is used to determine the context of the log message.
|
|
127
|
-
* @returns The name of the caller function or class.
|
|
128
|
-
*/
|
|
129
|
-
function getCallee(): string {
|
|
130
|
-
const stack = new Error().stack?.split('\n') ?? [];
|
|
131
|
-
const caller = stack[3]
|
|
132
|
-
?.trim()
|
|
133
|
-
.match(/at (.+?)(?:\..+)? .+$/)
|
|
134
|
-
?.[1]
|
|
135
|
-
?.replace("Object", "")
|
|
136
|
-
.replace(/^_/, "")
|
|
137
|
-
|| "App";
|
|
138
|
-
return caller;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Checks if the current log level allows logging the specified level.
|
|
143
|
-
* This function compares the current log level with the specified level to determine if logging should occur.
|
|
144
|
-
* @param level - The log level to check.
|
|
145
|
-
* @returns A boolean indicating whether the log level is enabled.
|
|
146
|
-
*/
|
|
147
|
-
function canLog(level: LogLevel): boolean {
|
|
148
|
-
return logLevels.has(level);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Writes a log message to a file asynchronously to avoid blocking the event loop.
|
|
153
|
-
* It batches messages if writing is already in progress.
|
|
154
|
-
* @param filepath - The path to the log file.
|
|
155
|
-
*/
|
|
156
|
-
function processLogQueue(filepath: string): void {
|
|
157
|
-
const state = fileStates.get(filepath);
|
|
158
|
-
|
|
159
|
-
if(!state || state.isWriting || state.queue.length === 0) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
state.isWriting = true;
|
|
164
|
-
|
|
165
|
-
// Optimization: Grab all pending messages to write in one go
|
|
166
|
-
const messagesToWrite = state.queue.join('\n') + '\n';
|
|
167
|
-
state.queue = []; // Clear the queue immediately
|
|
168
|
-
|
|
169
|
-
const dir = path.dirname(filepath);
|
|
170
|
-
|
|
171
|
-
// Using async IO to allow other operations
|
|
172
|
-
fs.mkdir(dir, { recursive: true }, (err) => {
|
|
173
|
-
if(err) {
|
|
174
|
-
console.error(`[Logger] Failed to create directory ${dir}`, err);
|
|
175
|
-
state.isWriting = false;
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
fs.appendFile(filepath, messagesToWrite, { encoding: "utf-8" }, (err) => {
|
|
180
|
-
state.isWriting = false;
|
|
181
|
-
|
|
182
|
-
if(err) {
|
|
183
|
-
console.error(`[Logger] Failed to write log to ${filepath}`, err);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// If new messages arrived while we were writing, process them now
|
|
187
|
-
if(state.queue.length > 0) {
|
|
188
|
-
processLogQueue(filepath);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Adds a message to the file queue and triggers processing.
|
|
196
|
-
*/
|
|
197
|
-
function enqueue(filepath: string, message: string): void {
|
|
198
|
-
if(!fileStates.has(filepath)) {
|
|
199
|
-
fileStates.set(filepath, { queue: [], isWriting: false });
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const state = fileStates.get(filepath)!;
|
|
203
|
-
state.queue.push(message);
|
|
204
|
-
|
|
205
|
-
processLogQueue(filepath);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
function output(level: LogLevel, args: any[]): void {
|
|
212
|
-
if(!canLog(level)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const callee = getCallee();
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
const prefix = getLogPrefix(callee, level, logLevelColors[level]);
|
|
220
|
-
const data = formattedArgs(prefix, args, logLevelColors[level]);
|
|
221
|
-
|
|
222
|
-
logLevelChannel[level](prefix, ...data);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
{
|
|
226
|
-
const prefix = getLogPrefix(callee, level);
|
|
227
|
-
const data = formattedArgs(prefix, args);
|
|
228
|
-
|
|
229
|
-
const filepath = fileSettings.get(level)?.filepath;
|
|
230
|
-
|
|
231
|
-
if(filepath) {
|
|
232
|
-
const message = prefix + " " + data.join(" ").replace(/\x1b\[[0-9;]*m/g, ''); // Remove ANSI codes
|
|
233
|
-
enqueue(filepath, message);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
export namespace Logger {
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Sets the log level for the logger.
|
|
244
|
-
* This function allows you to change the log level dynamically at runtime.
|
|
245
|
-
* This won't affect the startup logs.
|
|
246
|
-
*
|
|
247
|
-
* If the parameter is a single LogLevel, all log levels with equal or higher severity will be enabled.
|
|
248
|
-
|
|
249
|
-
* If the parameter is an array of LogLevels, only the specified levels will be enabled.
|
|
250
|
-
*
|
|
251
|
-
* @param level Sets the log level for the logger.
|
|
252
|
-
*/
|
|
253
|
-
export function setLogLevel(level: LogLevel | LogLevel[]): void {
|
|
254
|
-
logLevels.clear();
|
|
255
|
-
|
|
256
|
-
if(Array.isArray(level)) {
|
|
257
|
-
for(const lvl of level) {
|
|
258
|
-
logLevels.add(lvl);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
const targetRank = logLevelRank[level];
|
|
263
|
-
|
|
264
|
-
for(const [lvl, rank] of Object.entries(logLevelRank) as [LogLevel, number][]) {
|
|
265
|
-
if(rank >= targetRank) {
|
|
266
|
-
logLevels.add(lvl);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Logs a message to the console with log level LOG.
|
|
274
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
275
|
-
* It uses different colors for different log levels to enhance readability.
|
|
276
|
-
* @param args The arguments to log.
|
|
277
|
-
*/
|
|
278
|
-
export function log(...args: any[]): void {
|
|
279
|
-
output("log", args);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Logs a message to the console with log level INFO.
|
|
284
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
285
|
-
* It uses different colors for different log levels to enhance readability.
|
|
286
|
-
* @param args The arguments to log.
|
|
287
|
-
*/
|
|
288
|
-
export function info(...args: any[]): void {
|
|
289
|
-
output("info", args);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Logs a message to the console with log level WARN.
|
|
294
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
295
|
-
* It uses different colors for different log levels to enhance readability.
|
|
296
|
-
* @param args The arguments to log.
|
|
297
|
-
*/
|
|
298
|
-
export function warn(...args: any[]): void {
|
|
299
|
-
output("warn", args);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Logs a message to the console with log level ERROR.
|
|
304
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
305
|
-
* It uses different colors for different log levels to enhance readability.
|
|
306
|
-
* @param args The arguments to log.
|
|
307
|
-
*/
|
|
308
|
-
export function error(...args: any[]): void {
|
|
309
|
-
output("error", args);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Logs a message to the console with log level ERROR and a grey color scheme.
|
|
314
|
-
*/
|
|
315
|
-
export function errorStack(...args: any[]): void {
|
|
316
|
-
output("error", args);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Logs a message to the console with log level DEBUG.
|
|
321
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
322
|
-
* It uses different colors for different log levels to enhance readability.
|
|
323
|
-
* @param args The arguments to log.
|
|
324
|
-
*/
|
|
325
|
-
export function debug(...args: any[]): void {
|
|
326
|
-
output("debug", args);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Logs a message to the console with log level COMMENT.
|
|
331
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
332
|
-
* It uses different colors for different log levels to enhance readability.
|
|
333
|
-
* @param args The arguments to log.
|
|
334
|
-
*/
|
|
335
|
-
export function comment(...args: any[]): void {
|
|
336
|
-
output("comment", args);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Logs a message to the console with log level CRITICAL.
|
|
341
|
-
* This function formats the message with a timestamp, process ID, and the name of the caller function or class.
|
|
342
|
-
* It uses different colors for different log levels to enhance readability.
|
|
343
|
-
* @param args The arguments to log.
|
|
344
|
-
*/
|
|
345
|
-
export function critical(...args: any[]): void {
|
|
346
|
-
output("critical", args);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Enables logging to a file output for the specified log levels.
|
|
351
|
-
* @param filepath The path to the log file.
|
|
352
|
-
* @param levels The log levels to enable file logging for. Defaults to all levels.
|
|
353
|
-
*/
|
|
354
|
-
export function enableFileLogging(filepath: string, levels: LogLevel[] = ["debug", "comment", "log", "info", "warn", "error", "critical"]): void {
|
|
355
|
-
for(const level of levels) {
|
|
356
|
-
fileSettings.set(level, { filepath });
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Disables logging to a file output for the specified log levels.
|
|
362
|
-
* @param levels The log levels to disable file logging for. Defaults to all levels.
|
|
363
|
-
*/
|
|
364
|
-
export function disableFileLogging(levels: LogLevel[] = ["debug", "comment", "log", "info", "warn", "error", "critical"]): void {
|
|
365
|
-
for(const level of levels) {
|
|
366
|
-
fileSettings.delete(level);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
export const colors = {
|
|
372
|
-
black: "\x1b[0;30m",
|
|
373
|
-
grey: "\x1b[0;37m",
|
|
374
|
-
red: "\x1b[0;31m",
|
|
375
|
-
green: "\x1b[0;32m",
|
|
376
|
-
brown: "\x1b[0;33m",
|
|
377
|
-
blue: "\x1b[0;34m",
|
|
378
|
-
purple: "\x1b[0;35m",
|
|
379
|
-
|
|
380
|
-
darkGrey: "\x1b[1;30m",
|
|
381
|
-
lightRed: "\x1b[1;31m",
|
|
382
|
-
lightGreen: "\x1b[1;32m",
|
|
383
|
-
yellow: "\x1b[1;33m",
|
|
384
|
-
lightBlue: "\x1b[1;34m",
|
|
385
|
-
magenta: "\x1b[1;35m",
|
|
386
|
-
cyan: "\x1b[1;36m",
|
|
387
|
-
white: "\x1b[1;37m",
|
|
388
|
-
|
|
389
|
-
initial: "\x1b[0m"
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const fileSettings: Map<LogLevel, { filepath: string }> = new Map();
|
|
395
|
-
const fileStates: Map<string, FileLogState> = new Map(); // filepath -> state
|
|
396
|
-
|
|
397
|
-
const logLevels: Set<LogLevel> = new Set();
|
|
398
|
-
|
|
399
|
-
const logLevelRank: Record<LogLevel, number> = {
|
|
400
|
-
debug: 0,
|
|
401
|
-
comment: 1,
|
|
402
|
-
log: 2,
|
|
403
|
-
info: 3,
|
|
404
|
-
warn: 4,
|
|
405
|
-
error: 5,
|
|
406
|
-
critical: 6,
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const logLevelColors: Record<LogLevel, string> = {
|
|
410
|
-
debug: Logger.colors.purple,
|
|
411
|
-
comment: Logger.colors.grey,
|
|
412
|
-
log: Logger.colors.green,
|
|
413
|
-
info: Logger.colors.blue,
|
|
414
|
-
warn: Logger.colors.brown,
|
|
415
|
-
error: Logger.colors.red,
|
|
416
|
-
critical: Logger.colors.lightRed,
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
const logLevelChannel: Record<LogLevel, (message?: any, ...optionalParams: any[]) => void> = {
|
|
420
|
-
debug: console.debug,
|
|
421
|
-
comment: console.debug,
|
|
422
|
-
log: console.log,
|
|
423
|
-
info: console.info,
|
|
424
|
-
warn: console.warn,
|
|
425
|
-
error: console.error,
|
|
426
|
-
critical: console.error,
|
|
427
|
-
};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
Logger.setLogLevel("debug");
|