content-security-toolkit 1.0.1 → 1.0.2

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.
Files changed (58) hide show
  1. package/README.md +22 -0
  2. package/dist/core/mediator/handlers/baseEventHandler.d.ts +65 -0
  3. package/dist/core/mediator/handlers/baseEventHandler.js +99 -0
  4. package/dist/core/mediator/handlers/index.d.ts +9 -0
  5. package/dist/core/mediator/handlers/index.js +34 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +1 -0
  8. package/dist/otel.d.ts +24 -0
  9. package/dist/otel.js +87 -0
  10. package/dist/strategies/AbstractStrategy.mediator.d.ts +162 -0
  11. package/dist/strategies/AbstractStrategy.mediator.js +349 -0
  12. package/dist/strategies/DevToolsStrategy copy.d.ts +85 -0
  13. package/dist/strategies/DevToolsStrategy copy.js +362 -0
  14. package/dist/strategies/DevToolsStrategy-detectorManager.d.ts +70 -0
  15. package/dist/strategies/DevToolsStrategy-detectorManager.js +309 -0
  16. package/dist/strategies/DevToolsStrategy-simple.d.ts +75 -0
  17. package/dist/strategies/DevToolsStrategy-simple.js +366 -0
  18. package/dist/strategies/StrategyRegistry.d.ts +133 -0
  19. package/dist/strategies/StrategyRegistry.js +379 -0
  20. package/dist/utils/base/LoggableComponent.d.ts +62 -0
  21. package/dist/utils/base/LoggableComponent.js +95 -0
  22. package/dist/utils/debuggerDetector/debuggerDetectionWorker.d.ts +6 -0
  23. package/dist/utils/debuggerDetector/debuggerDetectionWorker.js +24 -0
  24. package/dist/utils/debuggerDetector/debuggerDetector.d.ts +55 -0
  25. package/dist/utils/debuggerDetector/debuggerDetector.js +158 -0
  26. package/dist/utils/debuggerDetector/firefoxDetector.d.ts +8 -0
  27. package/dist/utils/debuggerDetector/firefoxDetector.js +64 -0
  28. package/dist/utils/detection.d.ts +29 -0
  29. package/dist/utils/detection.js +267 -0
  30. package/dist/utils/detectors/debuggerDetectionWorker.d.ts +6 -0
  31. package/dist/utils/detectors/debuggerDetectionWorker.js +24 -0
  32. package/dist/utils/detectors/firefoxDetector.d.ts +8 -0
  33. package/dist/utils/detectors/firefoxDetector.js +64 -0
  34. package/dist/utils/logging/LogLevel.d.ts +21 -0
  35. package/dist/utils/logging/LogLevel.js +46 -0
  36. package/dist/utils/logging/LoggingConfig.d.ts +68 -0
  37. package/dist/utils/logging/LoggingConfig.js +64 -0
  38. package/dist/utils/logging/LoggingFactory.d.ts +22 -0
  39. package/dist/utils/logging/LoggingFactory.js +61 -0
  40. package/dist/utils/logging/LoggingService.d.ts +235 -0
  41. package/dist/utils/logging/LoggingService.js +385 -0
  42. package/dist/utils/logging/SimpleLoggingService.d.ts +39 -0
  43. package/dist/utils/logging/SimpleLoggingService.js +58 -0
  44. package/dist/utils/logging/advanced/LogLevel.d.ts +21 -0
  45. package/dist/utils/logging/advanced/LogLevel.js +46 -0
  46. package/dist/utils/logging/advanced/LoggingConfig.d.ts +68 -0
  47. package/dist/utils/logging/advanced/LoggingConfig.js +64 -0
  48. package/dist/utils/logging/advanced/LoggingFactory.d.ts +22 -0
  49. package/dist/utils/logging/advanced/LoggingFactory.js +61 -0
  50. package/dist/utils/logging/advanced/LoggingService.d.ts +235 -0
  51. package/dist/utils/logging/advanced/LoggingService.js +385 -0
  52. package/dist/utils/protectedContentManager-simple.d.ts +86 -0
  53. package/dist/utils/protectedContentManager-simple.js +180 -0
  54. package/dist/utils/securityOverlayManager-observer-pause.d.ts +283 -0
  55. package/dist/utils/securityOverlayManager-observer-pause.js +878 -0
  56. package/dist/utils/securityOverlayManager-simple.d.ts +197 -0
  57. package/dist/utils/securityOverlayManager-simple.js +552 -0
  58. package/package.json +1 -1
@@ -0,0 +1,61 @@
1
+ import { LoggingService } from "./LoggingService";
2
+ import { getComponentLogLevel, getLoggingConfig } from "./LoggingConfig";
3
+ /**
4
+ * Factory for creating LoggingService instances
5
+ */
6
+ export class LoggingFactory {
7
+ /**
8
+ * Get a LoggingService instance for a component
9
+ * @param componentName Component name
10
+ * @returns LoggingService instance
11
+ */
12
+ static getLogger(componentName) {
13
+ // Check if we already have an instance for this component
14
+ if (this.instances.has(componentName)) {
15
+ return this.instances.get(componentName);
16
+ }
17
+ // Get the global config
18
+ const config = getLoggingConfig();
19
+ // Create a new instance
20
+ const logger = new LoggingService({
21
+ componentName,
22
+ level: getComponentLogLevel(componentName),
23
+ useColors: config.useColors,
24
+ includeTimestamps: config.includeTimestamps,
25
+ includeComponentName: config.includeComponentName,
26
+ });
27
+ // Apply global settings
28
+ if (config.enabledComponents !== null) {
29
+ logger.setEnabledComponents(config.enabledComponents);
30
+ }
31
+ if (config.focusedLevel !== null) {
32
+ logger.focusLevel(config.focusedLevel);
33
+ }
34
+ // Store the instance
35
+ this.instances.set(componentName, logger);
36
+ return logger;
37
+ }
38
+ /**
39
+ * Update all existing logger instances with current configuration
40
+ */
41
+ static updateAllLoggers() {
42
+ const config = getLoggingConfig();
43
+ for (const [componentName, logger] of this.instances.entries()) {
44
+ logger.setLevel(getComponentLogLevel(componentName));
45
+ if (config.enabledComponents !== null) {
46
+ logger.setEnabledComponents(config.enabledComponents);
47
+ }
48
+ if (config.focusedLevel !== null) {
49
+ logger.focusLevel(config.focusedLevel);
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * Get all registered logger instances
55
+ * @returns Map of component names to logger instances
56
+ */
57
+ static getAllLoggers() {
58
+ return new Map(this.instances);
59
+ }
60
+ }
61
+ LoggingFactory.instances = new Map();
@@ -0,0 +1,235 @@
1
+ import { LogLevel } from "./LogLevel";
2
+ /**
3
+ * Options for the LoggingService
4
+ */
5
+ export interface LoggingOptions {
6
+ /**
7
+ * Component name for log prefixing
8
+ */
9
+ componentName: string;
10
+ /**
11
+ * Initial log level
12
+ * @default LogLevel.INFO
13
+ */
14
+ level?: LogLevel;
15
+ /**
16
+ * Whether logging is enabled
17
+ * @default true
18
+ */
19
+ enabled?: boolean;
20
+ /**
21
+ * Whether to use colors in console output
22
+ * @default true
23
+ */
24
+ useColors?: boolean;
25
+ /**
26
+ * Whether to include timestamps in logs
27
+ * @default true
28
+ */
29
+ includeTimestamps?: boolean;
30
+ /**
31
+ * Whether to include component name in logs
32
+ * @default true
33
+ */
34
+ includeComponentName?: boolean;
35
+ }
36
+ /**
37
+ * Performance timing result
38
+ */
39
+ export interface TimingResult<T> {
40
+ result: T;
41
+ duration: number;
42
+ }
43
+ /**
44
+ * Advanced logging service with context tracking, filtering, and performance measurement
45
+ */
46
+ export declare class LoggingService {
47
+ private componentName;
48
+ private currentLevel;
49
+ private enabled;
50
+ private useColors;
51
+ private includeTimestamps;
52
+ private includeComponentName;
53
+ private contextStack;
54
+ private contextDepth;
55
+ private enabledComponents;
56
+ private focusedLevel;
57
+ private groupDepth;
58
+ /**
59
+ * Create a new LoggingService
60
+ * @param options Configuration options
61
+ */
62
+ constructor(options: LoggingOptions);
63
+ /**
64
+ * Set the current log level threshold
65
+ * @param level New log level
66
+ */
67
+ setLevel(level: LogLevel): void;
68
+ /**
69
+ * Get the current log level
70
+ * @returns The current log level
71
+ */
72
+ getLevel(): LogLevel;
73
+ /**
74
+ * Get the current log level name
75
+ * @returns The current log level name
76
+ */
77
+ getLevelName(): string;
78
+ /**
79
+ * Enable or disable logging
80
+ * @param enabled Whether logging should be enabled
81
+ */
82
+ setEnabled(enabled: boolean): void;
83
+ /**
84
+ * Check if logging is enabled
85
+ * @returns Whether logging is enabled
86
+ */
87
+ isEnabled(): boolean;
88
+ /**
89
+ * Set components to show logs for
90
+ * @param components Array of component names to enable, or null to enable all
91
+ */
92
+ setEnabledComponents(components: string[] | null): void;
93
+ /**
94
+ * Focus on a specific log level
95
+ * @param level Level to focus on, or null to show all levels
96
+ */
97
+ focusLevel(level: LogLevel | null): void;
98
+ /**
99
+ * Increase context depth (call when entering a loop or nested function)
100
+ * @param contextName Optional name for the context
101
+ * @returns A function that exits this context when called
102
+ */
103
+ enterContext(contextName?: string): () => void;
104
+ /**
105
+ * Decrease context depth (call when exiting a loop or nested function)
106
+ */
107
+ exitContext(): void;
108
+ /**
109
+ * Execute a function within a named context
110
+ * @param contextName Name for the context
111
+ * @param fn Function to execute
112
+ * @returns The result of the function
113
+ */
114
+ withContext<T>(contextName: string, fn: () => T): T;
115
+ /**
116
+ * Execute an async function within a named context
117
+ * @param contextName Name for the context
118
+ * @param fn Async function to execute
119
+ * @returns Promise resolving to the result of the function
120
+ */
121
+ withContextAsync<T>(contextName: string, fn: () => Promise<T>): Promise<T>;
122
+ /**
123
+ * Start a console group
124
+ * @param label Label for the group
125
+ * @param collapsed Whether the group should be collapsed
126
+ */
127
+ startGroup(label: string, collapsed?: boolean): void;
128
+ /**
129
+ * End the current console group
130
+ */
131
+ endGroup(): void;
132
+ /**
133
+ * Execute a function within a console group
134
+ * @param label Label for the group
135
+ * @param fn Function to execute
136
+ * @param collapsed Whether the group should be collapsed
137
+ * @returns The result of the function
138
+ */
139
+ group<T>(label: string, fn: () => T, collapsed?: boolean): T;
140
+ /**
141
+ * Execute an async function within a console group
142
+ * @param label Label for the group
143
+ * @param fn Async function to execute
144
+ * @param collapsed Whether the group should be collapsed
145
+ * @returns Promise resolving to the result of the function
146
+ */
147
+ groupAsync<T>(label: string, fn: () => Promise<T>, collapsed?: boolean): Promise<T>;
148
+ /**
149
+ * Measure the execution time of a function
150
+ * @param label Label for the timing
151
+ * @param fn Function to measure
152
+ * @returns Object containing the result and duration
153
+ */
154
+ time<T>(label: string, fn: () => T): TimingResult<T>;
155
+ /**
156
+ * Measure the execution time of an async function
157
+ * @param label Label for the timing
158
+ * @param fn Async function to measure
159
+ * @returns Promise resolving to an object containing the result and duration
160
+ */
161
+ timeAsync<T>(label: string, fn: () => Promise<T>): Promise<TimingResult<T>>;
162
+ /**
163
+ * Log with automatic level adjustment based on context depth
164
+ * @param message Message to log
165
+ * @param args Additional arguments to log
166
+ */
167
+ logWithContext(message: string, ...args: unknown[]): void;
168
+ /**
169
+ * Main logging method
170
+ * @param level Log level
171
+ * @param message Message to log
172
+ * @param args Additional arguments to log
173
+ */
174
+ log(level: LogLevel, message: string, ...args: unknown[]): void;
175
+ /**
176
+ * Log an error message
177
+ * @param message Error message
178
+ * @param args Additional arguments to log
179
+ */
180
+ error(message: string, ...args: unknown[]): void;
181
+ /**
182
+ * Log a warning message
183
+ * @param message Warning message
184
+ * @param args Additional arguments to log
185
+ */
186
+ warn(message: string, ...args: unknown[]): void;
187
+ /**
188
+ * Log an info message
189
+ * @param message Info message
190
+ * @param args Additional arguments to log
191
+ */
192
+ info(message: string, ...args: unknown[]): void;
193
+ /**
194
+ * Log a debug message
195
+ * @param message Debug message
196
+ * @param args Additional arguments to log
197
+ */
198
+ debug(message: string, ...args: unknown[]): void;
199
+ /**
200
+ * Log a trace message
201
+ * @param message Trace message
202
+ * @param args Additional arguments to log
203
+ */
204
+ trace(message: string, ...args: unknown[]): void;
205
+ /**
206
+ * Log a verbose message
207
+ * @param message Verbose message
208
+ * @param args Additional arguments to log
209
+ */
210
+ verbose(message: string, ...args: unknown[]): void;
211
+ /**
212
+ * Check if a message should be logged
213
+ * @param level Log level of the message
214
+ * @returns Whether the message should be logged
215
+ */
216
+ private shouldLog;
217
+ /**
218
+ * Format a log message
219
+ * @param level Log level
220
+ * @param message Message to format
221
+ * @returns Formatted message
222
+ */
223
+ private formatMessage;
224
+ /**
225
+ * Get the current timestamp as a string
226
+ * @returns Formatted timestamp
227
+ */
228
+ private getTimestamp;
229
+ /**
230
+ * Get prefix for log level
231
+ * @param level Log level
232
+ * @returns Formatted prefix
233
+ */
234
+ private getLevelPrefix;
235
+ }
@@ -0,0 +1,385 @@
1
+ import { LogLevel, getLogLevelName } from "./LogLevel";
2
+ /**
3
+ * Advanced logging service with context tracking, filtering, and performance measurement
4
+ */
5
+ export class LoggingService {
6
+ /**
7
+ * Create a new LoggingService
8
+ * @param options Configuration options
9
+ */
10
+ constructor(options) {
11
+ // Context tracking
12
+ this.contextStack = [];
13
+ this.contextDepth = 0;
14
+ // Component filtering
15
+ this.enabledComponents = null;
16
+ // Level focusing
17
+ this.focusedLevel = null;
18
+ // Console group tracking
19
+ this.groupDepth = 0;
20
+ this.componentName = options.componentName;
21
+ this.currentLevel = options.level ?? LogLevel.INFO;
22
+ this.enabled = options.enabled ?? true;
23
+ this.useColors = options.useColors ?? true;
24
+ this.includeTimestamps = options.includeTimestamps ?? true;
25
+ this.includeComponentName = options.includeComponentName ?? true;
26
+ }
27
+ /**
28
+ * Set the current log level threshold
29
+ * @param level New log level
30
+ */
31
+ setLevel(level) {
32
+ this.currentLevel = level;
33
+ }
34
+ /**
35
+ * Get the current log level
36
+ * @returns The current log level
37
+ */
38
+ getLevel() {
39
+ return this.currentLevel;
40
+ }
41
+ /**
42
+ * Get the current log level name
43
+ * @returns The current log level name
44
+ */
45
+ getLevelName() {
46
+ return getLogLevelName(this.currentLevel);
47
+ }
48
+ /**
49
+ * Enable or disable logging
50
+ * @param enabled Whether logging should be enabled
51
+ */
52
+ setEnabled(enabled) {
53
+ this.enabled = enabled;
54
+ }
55
+ /**
56
+ * Check if logging is enabled
57
+ * @returns Whether logging is enabled
58
+ */
59
+ isEnabled() {
60
+ return this.enabled;
61
+ }
62
+ /**
63
+ * Set components to show logs for
64
+ * @param components Array of component names to enable, or null to enable all
65
+ */
66
+ setEnabledComponents(components) {
67
+ if (components === null) {
68
+ this.enabledComponents = null;
69
+ }
70
+ else {
71
+ this.enabledComponents = new Set(components);
72
+ }
73
+ }
74
+ /**
75
+ * Focus on a specific log level
76
+ * @param level Level to focus on, or null to show all levels
77
+ */
78
+ focusLevel(level) {
79
+ this.focusedLevel = level;
80
+ }
81
+ /**
82
+ * Increase context depth (call when entering a loop or nested function)
83
+ * @param contextName Optional name for the context
84
+ * @returns A function that exits this context when called
85
+ */
86
+ enterContext(contextName = "context") {
87
+ this.contextDepth++;
88
+ const context = {
89
+ name: contextName,
90
+ startTime: performance.now(),
91
+ depth: this.contextDepth,
92
+ };
93
+ this.contextStack.push(context);
94
+ this.trace(`Entering ${contextName}`);
95
+ // Return a function that exits this context
96
+ return () => {
97
+ this.exitContext();
98
+ };
99
+ }
100
+ /**
101
+ * Decrease context depth (call when exiting a loop or nested function)
102
+ */
103
+ exitContext() {
104
+ if (this.contextStack.length > 0) {
105
+ const context = this.contextStack.pop();
106
+ this.contextDepth = Math.max(0, this.contextDepth - 1);
107
+ const duration = performance.now() - context.startTime;
108
+ this.trace(`Exiting ${context.name} (took ${duration.toFixed(2)}ms)`);
109
+ }
110
+ }
111
+ /**
112
+ * Execute a function within a named context
113
+ * @param contextName Name for the context
114
+ * @param fn Function to execute
115
+ * @returns The result of the function
116
+ */
117
+ withContext(contextName, fn) {
118
+ const exitFn = this.enterContext(contextName);
119
+ try {
120
+ return fn();
121
+ }
122
+ finally {
123
+ exitFn();
124
+ }
125
+ }
126
+ /**
127
+ * Execute an async function within a named context
128
+ * @param contextName Name for the context
129
+ * @param fn Async function to execute
130
+ * @returns Promise resolving to the result of the function
131
+ */
132
+ async withContextAsync(contextName, fn) {
133
+ const exitFn = this.enterContext(contextName);
134
+ try {
135
+ return await fn();
136
+ }
137
+ finally {
138
+ exitFn();
139
+ }
140
+ }
141
+ /**
142
+ * Start a console group
143
+ * @param label Label for the group
144
+ * @param collapsed Whether the group should be collapsed
145
+ */
146
+ startGroup(label, collapsed = false) {
147
+ if (!this.shouldLog(LogLevel.INFO))
148
+ return;
149
+ this.groupDepth++;
150
+ if (collapsed) {
151
+ console.groupCollapsed(this.formatMessage(LogLevel.INFO, label));
152
+ }
153
+ else {
154
+ console.group(this.formatMessage(LogLevel.INFO, label));
155
+ }
156
+ }
157
+ /**
158
+ * End the current console group
159
+ */
160
+ endGroup() {
161
+ if (this.groupDepth > 0) {
162
+ console.groupEnd();
163
+ this.groupDepth--;
164
+ }
165
+ }
166
+ /**
167
+ * Execute a function within a console group
168
+ * @param label Label for the group
169
+ * @param fn Function to execute
170
+ * @param collapsed Whether the group should be collapsed
171
+ * @returns The result of the function
172
+ */
173
+ group(label, fn, collapsed = false) {
174
+ this.startGroup(label, collapsed);
175
+ try {
176
+ return fn();
177
+ }
178
+ finally {
179
+ this.endGroup();
180
+ }
181
+ }
182
+ /**
183
+ * Execute an async function within a console group
184
+ * @param label Label for the group
185
+ * @param fn Async function to execute
186
+ * @param collapsed Whether the group should be collapsed
187
+ * @returns Promise resolving to the result of the function
188
+ */
189
+ async groupAsync(label, fn, collapsed = false) {
190
+ this.startGroup(label, collapsed);
191
+ try {
192
+ return await fn();
193
+ }
194
+ finally {
195
+ this.endGroup();
196
+ }
197
+ }
198
+ /**
199
+ * Measure the execution time of a function
200
+ * @param label Label for the timing
201
+ * @param fn Function to measure
202
+ * @returns Object containing the result and duration
203
+ */
204
+ time(label, fn) {
205
+ const start = performance.now();
206
+ const result = fn();
207
+ const duration = performance.now() - start;
208
+ this.info(`${label} took ${duration.toFixed(2)}ms`);
209
+ return { result, duration };
210
+ }
211
+ /**
212
+ * Measure the execution time of an async function
213
+ * @param label Label for the timing
214
+ * @param fn Async function to measure
215
+ * @returns Promise resolving to an object containing the result and duration
216
+ */
217
+ async timeAsync(label, fn) {
218
+ const start = performance.now();
219
+ const result = await fn();
220
+ const duration = performance.now() - start;
221
+ this.info(`${label} took ${duration.toFixed(2)}ms`);
222
+ return { result, duration };
223
+ }
224
+ /**
225
+ * Log with automatic level adjustment based on context depth
226
+ * @param message Message to log
227
+ * @param args Additional arguments to log
228
+ */
229
+ logWithContext(message, ...args) {
230
+ // Adjust level based on nesting - deeper nesting means more detailed level
231
+ const adjustedLevel = Math.min(LogLevel.VERBOSE, LogLevel.INFO + this.contextDepth);
232
+ this.log(adjustedLevel, message, ...args);
233
+ }
234
+ /**
235
+ * Main logging method
236
+ * @param level Log level
237
+ * @param message Message to log
238
+ * @param args Additional arguments to log
239
+ */
240
+ log(level, message, ...args) {
241
+ if (!this.shouldLog(level))
242
+ return;
243
+ const formattedMessage = this.formatMessage(level, message);
244
+ switch (level) {
245
+ case LogLevel.ERROR:
246
+ console.error(formattedMessage, ...args);
247
+ break;
248
+ case LogLevel.WARN:
249
+ console.warn(formattedMessage, ...args);
250
+ break;
251
+ default:
252
+ console.log(formattedMessage, ...args);
253
+ break;
254
+ }
255
+ }
256
+ /**
257
+ * Log an error message
258
+ * @param message Error message
259
+ * @param args Additional arguments to log
260
+ */
261
+ error(message, ...args) {
262
+ this.log(LogLevel.ERROR, message, ...args);
263
+ }
264
+ /**
265
+ * Log a warning message
266
+ * @param message Warning message
267
+ * @param args Additional arguments to log
268
+ */
269
+ warn(message, ...args) {
270
+ this.log(LogLevel.WARN, message, ...args);
271
+ }
272
+ /**
273
+ * Log an info message
274
+ * @param message Info message
275
+ * @param args Additional arguments to log
276
+ */
277
+ info(message, ...args) {
278
+ this.log(LogLevel.INFO, message, ...args);
279
+ }
280
+ /**
281
+ * Log a debug message
282
+ * @param message Debug message
283
+ * @param args Additional arguments to log
284
+ */
285
+ debug(message, ...args) {
286
+ this.log(LogLevel.DEBUG, message, ...args);
287
+ }
288
+ /**
289
+ * Log a trace message
290
+ * @param message Trace message
291
+ * @param args Additional arguments to log
292
+ */
293
+ trace(message, ...args) {
294
+ this.log(LogLevel.TRACE, message, ...args);
295
+ }
296
+ /**
297
+ * Log a verbose message
298
+ * @param message Verbose message
299
+ * @param args Additional arguments to log
300
+ */
301
+ verbose(message, ...args) {
302
+ this.log(LogLevel.VERBOSE, message, ...args);
303
+ }
304
+ /**
305
+ * Check if a message should be logged
306
+ * @param level Log level of the message
307
+ * @returns Whether the message should be logged
308
+ */
309
+ shouldLog(level) {
310
+ // Always log errors and warnings, otherwise respect enabled flag
311
+ if (!this.enabled && level > LogLevel.WARN)
312
+ return false;
313
+ // If we're focusing on a specific level, only log messages at that level
314
+ if (this.focusedLevel !== null) {
315
+ return level === this.focusedLevel || level <= LogLevel.WARN;
316
+ }
317
+ // Otherwise, respect the level threshold
318
+ if (level > this.currentLevel && level > LogLevel.WARN)
319
+ return false;
320
+ // Check if component is enabled
321
+ if (this.enabledComponents !== null && !this.enabledComponents.has(this.componentName)) {
322
+ // Still allow errors and warnings
323
+ return level <= LogLevel.WARN;
324
+ }
325
+ return true;
326
+ }
327
+ /**
328
+ * Format a log message
329
+ * @param level Log level
330
+ * @param message Message to format
331
+ * @returns Formatted message
332
+ */
333
+ formatMessage(level, message) {
334
+ const parts = [];
335
+ // Add timestamp if enabled
336
+ if (this.includeTimestamps) {
337
+ parts.push(this.getTimestamp());
338
+ }
339
+ // Add level prefix
340
+ parts.push(this.getLevelPrefix(level));
341
+ // Add component name if enabled
342
+ if (this.includeComponentName) {
343
+ parts.push(this.componentName);
344
+ }
345
+ // Add indentation based on context depth
346
+ const indentation = " ".repeat(this.contextDepth);
347
+ // Combine all parts
348
+ return `${parts.join(" ")}: ${indentation}${message}`;
349
+ }
350
+ /**
351
+ * Get the current timestamp as a string
352
+ * @returns Formatted timestamp
353
+ */
354
+ getTimestamp() {
355
+ const now = new Date();
356
+ return `[${now.toISOString()}]`;
357
+ }
358
+ /**
359
+ * Get prefix for log level
360
+ * @param level Log level
361
+ * @returns Formatted prefix
362
+ */
363
+ getLevelPrefix(level) {
364
+ if (!this.useColors) {
365
+ return `[${getLogLevelName(level)}]`;
366
+ }
367
+ // Use colors for different levels
368
+ switch (level) {
369
+ case LogLevel.ERROR:
370
+ return "\x1b[31m[ERROR]\x1b[0m"; // Red
371
+ case LogLevel.WARN:
372
+ return "\x1b[33m[WARN]\x1b[0m"; // Yellow
373
+ case LogLevel.INFO:
374
+ return "\x1b[36m[INFO]\x1b[0m"; // Cyan
375
+ case LogLevel.DEBUG:
376
+ return "\x1b[32m[DEBUG]\x1b[0m"; // Green
377
+ case LogLevel.TRACE:
378
+ return "\x1b[35m[TRACE]\x1b[0m"; // Magenta
379
+ case LogLevel.VERBOSE:
380
+ return "\x1b[90m[VERBOSE]\x1b[0m"; // Gray
381
+ default:
382
+ return `[${getLogLevelName(level)}]`;
383
+ }
384
+ }
385
+ }