@adaas/a-utils 0.1.17 → 0.1.19
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/index.d.mts +964 -354
- package/dist/index.d.ts +964 -354
- package/dist/index.js +1426 -714
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1426 -714
- package/dist/index.mjs.map +1 -1
- package/examples/A-Channel-examples.ts +13 -11
- package/examples/A-Command-examples-2.ts +429 -0
- package/examples/A-Command-examples.ts +487 -202
- package/examples/A-StateMachine-examples.ts +609 -0
- package/package.json +3 -2
- package/src/index.ts +1 -2
- package/src/lib/A-Channel/A-Channel.component.ts +14 -74
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-Channel.types.ts +2 -10
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +25 -74
- package/src/lib/A-Command/A-Command.constants.ts +78 -23
- package/src/lib/A-Command/A-Command.entity.ts +447 -119
- package/src/lib/A-Command/A-Command.error.ts +11 -0
- package/src/lib/A-Command/A-Command.types.ts +96 -20
- package/src/lib/A-Command/A-CommandExecution.context.ts +0 -0
- package/src/lib/A-Command/README.md +164 -68
- package/src/lib/A-Config/A-Config.container.ts +2 -2
- package/src/lib/A-Config/A-Config.context.ts +19 -5
- package/src/lib/A-Config/components/ConfigReader.component.ts +1 -1
- package/src/lib/A-Logger/A-Logger.component.ts +211 -35
- package/src/lib/A-Logger/A-Logger.constants.ts +50 -10
- package/src/lib/A-Logger/A-Logger.env.ts +17 -1
- package/src/lib/A-Memory/A-Memory.component.ts +440 -0
- package/src/lib/A-Memory/A-Memory.constants.ts +49 -0
- package/src/lib/A-Memory/A-Memory.context.ts +14 -118
- package/src/lib/A-Memory/A-Memory.error.ts +21 -0
- package/src/lib/A-Memory/A-Memory.types.ts +21 -0
- package/src/lib/A-Operation/A-Operation.context.ts +58 -0
- package/src/lib/A-Operation/A-Operation.types.ts +47 -0
- package/src/lib/A-StateMachine/A-StateMachine.component.ts +258 -0
- package/src/lib/A-StateMachine/A-StateMachine.constants.ts +18 -0
- package/src/lib/A-StateMachine/A-StateMachine.error.ts +10 -0
- package/src/lib/A-StateMachine/A-StateMachine.types.ts +20 -0
- package/src/lib/A-StateMachine/A-StateMachineTransition.context.ts +41 -0
- package/src/lib/A-StateMachine/README.md +391 -0
- package/tests/A-Channel.test.ts +17 -14
- package/tests/A-Command.test.ts +548 -460
- package/tests/A-Logger.test.ts +8 -4
- package/tests/A-Memory.test.ts +151 -115
- package/tests/A-Schedule.test.ts +2 -2
- package/tests/A-StateMachine.test.ts +760 -0
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
A_LOGGER_ANSI,
|
|
9
9
|
A_LOGGER_TIME_FORMAT,
|
|
10
10
|
A_LOGGER_FORMAT,
|
|
11
|
-
A_LOGGER_ENV_KEYS
|
|
11
|
+
A_LOGGER_ENV_KEYS,
|
|
12
|
+
A_LOGGER_SAFE_RANDOM_COLORS
|
|
12
13
|
} from "./A-Logger.constants";
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -32,21 +33,33 @@ import {
|
|
|
32
33
|
*
|
|
33
34
|
* @example
|
|
34
35
|
* ```typescript
|
|
35
|
-
* // Basic usage with dependency injection
|
|
36
|
+
* // Basic usage with dependency injection (uses deterministic colors based on scope name)
|
|
36
37
|
* class MyService {
|
|
37
38
|
* constructor(@A_Inject(A_Logger) private logger: A_Logger) {}
|
|
38
39
|
*
|
|
39
40
|
* doSomething() {
|
|
40
|
-
* this.logger.
|
|
41
|
-
* this.logger.
|
|
41
|
+
* this.logger.info('Processing started'); // Uses scope-name-based colors, always shows
|
|
42
|
+
* this.logger.debug('Debug information'); // Only shows when debug level enabled
|
|
43
|
+
* this.logger.info('green', 'Custom message color'); // Green message, scope stays default
|
|
42
44
|
* this.logger.warning('Something might be wrong');
|
|
43
45
|
* this.logger.error(new Error('Something failed'));
|
|
44
46
|
* }
|
|
45
47
|
* }
|
|
46
48
|
*
|
|
47
|
-
* //
|
|
48
|
-
*
|
|
49
|
-
*
|
|
49
|
+
* // Same scope names will always get the same colors automatically
|
|
50
|
+
* const logger1 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets consistent colors
|
|
51
|
+
* const logger2 = new A_Logger(new A_Scope({name: 'UserService'})); // Gets same colors as logger1
|
|
52
|
+
*
|
|
53
|
+
* // Configuration via environment variables or A_Config (overrides automatic selection)
|
|
54
|
+
* process.env.A_LOGGER_DEFAULT_SCOPE_COLOR = 'magenta';
|
|
55
|
+
* process.env.A_LOGGER_DEFAULT_LOG_COLOR = 'green';
|
|
56
|
+
*
|
|
57
|
+
* // Or through A_Config instance
|
|
58
|
+
* const config = new A_Config({
|
|
59
|
+
* A_LOGGER_DEFAULT_SCOPE_COLOR: 'red',
|
|
60
|
+
* A_LOGGER_DEFAULT_LOG_COLOR: 'white'
|
|
61
|
+
* });
|
|
62
|
+
* const logger = new A_Logger(scope, config);
|
|
50
63
|
* ```
|
|
51
64
|
*/
|
|
52
65
|
export class A_Logger extends A_Component {
|
|
@@ -67,25 +80,122 @@ export class A_Logger extends A_Component {
|
|
|
67
80
|
*/
|
|
68
81
|
private readonly STANDARD_SCOPE_LENGTH;
|
|
69
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Default color for the scope portion of log messages
|
|
85
|
+
* This color is used for the scope brackets and content, and remains consistent
|
|
86
|
+
* for this logger instance regardless of message color overrides
|
|
87
|
+
*/
|
|
88
|
+
private readonly DEFAULT_SCOPE_COLOR: keyof typeof A_LOGGER_COLORS;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Default color for log message content when no explicit color is provided
|
|
92
|
+
* This color is used for the message body when logging without specifying a color
|
|
93
|
+
*/
|
|
94
|
+
private readonly DEFAULT_LOG_COLOR: keyof typeof A_LOGGER_COLORS;
|
|
95
|
+
|
|
70
96
|
// =============================================
|
|
71
97
|
// Constructor and Initialization
|
|
72
98
|
// =============================================
|
|
73
99
|
|
|
74
100
|
/**
|
|
75
101
|
* Initialize A_Logger with dependency injection
|
|
102
|
+
* Colors are configured through A_Config or generated randomly if not provided
|
|
76
103
|
*
|
|
77
104
|
* @param scope - The current scope context for message prefixing
|
|
78
|
-
* @param config - Optional configuration for log level filtering
|
|
105
|
+
* @param config - Optional configuration for log level filtering and color settings
|
|
79
106
|
*/
|
|
80
107
|
constructor(
|
|
81
108
|
@A_Inject(A_Scope) protected scope: A_Scope,
|
|
82
|
-
@A_Inject(A_Config) protected config?: A_Config<A_LoggerEnvVariablesType
|
|
109
|
+
@A_Inject(A_Config) protected config?: A_Config<A_LoggerEnvVariablesType>
|
|
83
110
|
) {
|
|
84
111
|
super();
|
|
85
112
|
this.COLORS = A_LOGGER_COLORS;
|
|
86
|
-
this.STANDARD_SCOPE_LENGTH = config?.get(
|
|
113
|
+
this.STANDARD_SCOPE_LENGTH = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_LENGTH) || A_LOGGER_DEFAULT_SCOPE_LENGTH;
|
|
114
|
+
|
|
115
|
+
// Get colors from config or generate deterministic colors based on scope name
|
|
116
|
+
const configScopeColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_COLOR) as keyof typeof A_LOGGER_COLORS;
|
|
117
|
+
const configLogColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_LOG_COLOR) as keyof typeof A_LOGGER_COLORS;
|
|
118
|
+
|
|
119
|
+
if (configScopeColor || configLogColor) {
|
|
120
|
+
// If any color is configured, use config values or fallback to scope-based selection
|
|
121
|
+
this.DEFAULT_SCOPE_COLOR = configScopeColor || this.generateColorFromScopeName(this.scope.name);
|
|
122
|
+
this.DEFAULT_LOG_COLOR = configLogColor || this.generateColorFromScopeName(this.scope.name );
|
|
123
|
+
} else {
|
|
124
|
+
// If no colors configured, generate complementary pair based on scope name
|
|
125
|
+
const complementaryColors = this.generateComplementaryColorsFromScope(this.scope.name);
|
|
126
|
+
this.DEFAULT_SCOPE_COLOR = complementaryColors.scopeColor;
|
|
127
|
+
this.DEFAULT_LOG_COLOR = complementaryColors.logColor;
|
|
128
|
+
}
|
|
87
129
|
}
|
|
88
130
|
|
|
131
|
+
// =============================================
|
|
132
|
+
// Color Generation Utilities
|
|
133
|
+
// =============================================
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Generate a simple hash from a string
|
|
137
|
+
* Used to create deterministic color selection based on scope name
|
|
138
|
+
*
|
|
139
|
+
* @param str - The string to hash
|
|
140
|
+
* @returns A numeric hash value
|
|
141
|
+
*/
|
|
142
|
+
private simpleHash(str: string): number {
|
|
143
|
+
let hash = 0;
|
|
144
|
+
for (let i = 0; i < str.length; i++) {
|
|
145
|
+
const char = str.charCodeAt(i);
|
|
146
|
+
hash = ((hash << 5) - hash) + char;
|
|
147
|
+
hash = hash & hash; // Convert to 32-bit integer
|
|
148
|
+
}
|
|
149
|
+
return Math.abs(hash);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Generate a deterministic color based on scope name
|
|
154
|
+
* Same scope names will always get the same color, but uses safe color palette
|
|
155
|
+
*
|
|
156
|
+
* @param scopeName - The scope name to generate color for
|
|
157
|
+
* @returns A color key from the safe colors palette
|
|
158
|
+
*/
|
|
159
|
+
private generateColorFromScopeName(scopeName: string): keyof typeof A_LOGGER_COLORS {
|
|
160
|
+
const safeColors = A_LOGGER_SAFE_RANDOM_COLORS;
|
|
161
|
+
const hash = this.simpleHash(scopeName);
|
|
162
|
+
const colorIndex = hash % safeColors.length;
|
|
163
|
+
return safeColors[colorIndex];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Generate a pair of complementary colors based on scope name
|
|
168
|
+
* Ensures visual harmony between scope and message colors while being deterministic
|
|
169
|
+
*
|
|
170
|
+
* @param scopeName - The scope name to base colors on
|
|
171
|
+
* @returns Object with scopeColor and logColor that work well together
|
|
172
|
+
*/
|
|
173
|
+
private generateComplementaryColorsFromScope(scopeName: string): { scopeColor: keyof typeof A_LOGGER_COLORS, logColor: keyof typeof A_LOGGER_COLORS } {
|
|
174
|
+
// Define color groups that work well together
|
|
175
|
+
const colorPairs = [
|
|
176
|
+
{ scopeColor: 'indigo' as const, logColor: 'lightBlue' as const },
|
|
177
|
+
{ scopeColor: 'deepBlue' as const, logColor: 'cyan' as const },
|
|
178
|
+
{ scopeColor: 'purple' as const, logColor: 'lavender' as const },
|
|
179
|
+
{ scopeColor: 'steelBlue' as const, logColor: 'skyBlue' as const },
|
|
180
|
+
{ scopeColor: 'slateBlue' as const, logColor: 'periwinkle' as const },
|
|
181
|
+
{ scopeColor: 'charcoal' as const, logColor: 'silver' as const },
|
|
182
|
+
{ scopeColor: 'violet' as const, logColor: 'brightMagenta' as const },
|
|
183
|
+
{ scopeColor: 'darkGray' as const, logColor: 'lightGray' as const },
|
|
184
|
+
{ scopeColor: 'cornflower' as const, logColor: 'powder' as const },
|
|
185
|
+
{ scopeColor: 'slate' as const, logColor: 'smoke' as const },
|
|
186
|
+
];
|
|
187
|
+
|
|
188
|
+
const hash = this.simpleHash(scopeName);
|
|
189
|
+
const pairIndex = hash % colorPairs.length;
|
|
190
|
+
return colorPairs[pairIndex];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// =============================================
|
|
194
|
+
// Factory Methods
|
|
195
|
+
// =============================================
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
89
199
|
// =============================================
|
|
90
200
|
// Scope and Formatting Utilities
|
|
91
201
|
// =============================================
|
|
@@ -101,13 +211,26 @@ export class A_Logger extends A_Component {
|
|
|
101
211
|
}
|
|
102
212
|
|
|
103
213
|
/**
|
|
104
|
-
* Get the formatted scope name with proper padding
|
|
105
|
-
* Ensures consistent width for all scope names in log output
|
|
214
|
+
* Get the formatted scope name with proper padding, centered within the container
|
|
215
|
+
* Ensures consistent width for all scope names in log output with centered alignment
|
|
106
216
|
*
|
|
107
|
-
* @returns
|
|
217
|
+
* @returns Centered and padded scope name for consistent formatting
|
|
108
218
|
*/
|
|
109
219
|
get formattedScope(): string {
|
|
110
|
-
|
|
220
|
+
const scopeName = this.scope.name;
|
|
221
|
+
const totalLength = this.STANDARD_SCOPE_LENGTH;
|
|
222
|
+
|
|
223
|
+
// If scope name is longer than standard length, truncate it
|
|
224
|
+
if (scopeName.length >= totalLength) {
|
|
225
|
+
return scopeName.substring(0, totalLength);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Calculate padding for centering
|
|
229
|
+
const totalPadding = totalLength - scopeName.length;
|
|
230
|
+
const leftPadding = Math.floor(totalPadding / 2);
|
|
231
|
+
const rightPadding = totalPadding - leftPadding;
|
|
232
|
+
|
|
233
|
+
return ' '.repeat(leftPadding) + scopeName + ' '.repeat(rightPadding);
|
|
111
234
|
}
|
|
112
235
|
|
|
113
236
|
|
|
@@ -119,17 +242,17 @@ export class A_Logger extends A_Component {
|
|
|
119
242
|
* Compile log arguments into formatted console output with colors and proper alignment
|
|
120
243
|
*
|
|
121
244
|
* This method handles the core formatting logic for all log messages:
|
|
122
|
-
* - Applies
|
|
245
|
+
* - Applies separate colors for scope and message content
|
|
123
246
|
* - Formats scope names with consistent padding
|
|
124
247
|
* - Handles different data types appropriately
|
|
125
248
|
* - Maintains proper indentation for multi-line content
|
|
126
249
|
*
|
|
127
|
-
* @param
|
|
250
|
+
* @param messageColor - The color key to apply to the message content
|
|
128
251
|
* @param args - Variable arguments to format and display
|
|
129
252
|
* @returns Array of formatted strings ready for console output
|
|
130
253
|
*/
|
|
131
254
|
compile(
|
|
132
|
-
|
|
255
|
+
messageColor: keyof typeof this.COLORS,
|
|
133
256
|
...args: any[]
|
|
134
257
|
): Array<string> {
|
|
135
258
|
const timeString = this.getTime();
|
|
@@ -137,8 +260,8 @@ export class A_Logger extends A_Component {
|
|
|
137
260
|
const isMultiArg = args.length > 1;
|
|
138
261
|
|
|
139
262
|
return [
|
|
140
|
-
// Header with
|
|
141
|
-
`${A_LOGGER_ANSI.PREFIX}${this.COLORS[
|
|
263
|
+
// Header with separate colors for scope and message content
|
|
264
|
+
`${A_LOGGER_ANSI.PREFIX}${this.COLORS[this.DEFAULT_SCOPE_COLOR]}${A_LOGGER_ANSI.SUFFIX}${A_LOGGER_FORMAT.SCOPE_OPEN}${this.formattedScope}${A_LOGGER_FORMAT.SCOPE_CLOSE}${A_LOGGER_ANSI.RESET} ${A_LOGGER_ANSI.PREFIX}${this.COLORS[messageColor]}${A_LOGGER_ANSI.SUFFIX}${A_LOGGER_FORMAT.TIME_OPEN}${timeString}${A_LOGGER_FORMAT.TIME_CLOSE}`,
|
|
142
265
|
|
|
143
266
|
// Top separator for multi-argument messages
|
|
144
267
|
isMultiArg ? '\n' + `${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}` : '',
|
|
@@ -219,7 +342,7 @@ export class A_Logger extends A_Component {
|
|
|
219
342
|
* Determine if a log message should be output based on configured log level
|
|
220
343
|
*
|
|
221
344
|
* Log level hierarchy:
|
|
222
|
-
* - debug: Shows all messages
|
|
345
|
+
* - debug: Shows all messages (debug, info, warning, error)
|
|
223
346
|
* - info: Shows info, warning, and error messages
|
|
224
347
|
* - warn: Shows warning and error messages only
|
|
225
348
|
* - error: Shows error messages only
|
|
@@ -228,14 +351,14 @@ export class A_Logger extends A_Component {
|
|
|
228
351
|
* @param logMethod - The type of log method being called
|
|
229
352
|
* @returns True if the message should be logged, false otherwise
|
|
230
353
|
*/
|
|
231
|
-
protected shouldLog(logMethod: '
|
|
232
|
-
const shouldLog: A_LoggerLevel = this.config?.get(A_LOGGER_ENV_KEYS.LOG_LEVEL) || '
|
|
354
|
+
protected shouldLog(logMethod: 'debug' | 'info' | 'warning' | 'error'): boolean {
|
|
355
|
+
const shouldLog: A_LoggerLevel = this.config?.get(A_LOGGER_ENV_KEYS.LOG_LEVEL) || 'info';
|
|
233
356
|
|
|
234
357
|
switch (shouldLog) {
|
|
235
358
|
case 'debug':
|
|
236
359
|
return true;
|
|
237
360
|
case 'info':
|
|
238
|
-
return logMethod === '
|
|
361
|
+
return logMethod === 'info' || logMethod === 'warning' || logMethod === 'error';
|
|
239
362
|
case 'warn':
|
|
240
363
|
return logMethod === 'warning' || logMethod === 'error';
|
|
241
364
|
case 'error':
|
|
@@ -253,36 +376,89 @@ export class A_Logger extends A_Component {
|
|
|
253
376
|
// =============================================
|
|
254
377
|
|
|
255
378
|
/**
|
|
256
|
-
*
|
|
379
|
+
* Debug logging method with optional color specification
|
|
380
|
+
* Only logs when debug level is enabled
|
|
257
381
|
*
|
|
258
382
|
* Supports two usage patterns:
|
|
259
|
-
* 1.
|
|
260
|
-
* 2.
|
|
383
|
+
* 1. debug(message, ...args) - Uses instance's default log color
|
|
384
|
+
* 2. debug(color, message, ...args) - Uses specified color for message content only
|
|
385
|
+
*
|
|
386
|
+
* Note: The scope color always remains the instance's default scope color,
|
|
387
|
+
* only the message content color changes when explicitly specified.
|
|
261
388
|
*
|
|
262
389
|
* @param color - Optional color key or the first message argument
|
|
263
390
|
* @param args - Additional arguments to log
|
|
264
391
|
*
|
|
265
392
|
* @example
|
|
266
393
|
* ```typescript
|
|
267
|
-
* logger.
|
|
268
|
-
* logger.
|
|
269
|
-
* logger.
|
|
394
|
+
* logger.debug('Debug information'); // Uses instance default colors
|
|
395
|
+
* logger.debug('gray', 'Debug message'); // Gray message, scope stays instance color
|
|
396
|
+
* logger.debug('Processing user:', { id: 1, name: 'John' });
|
|
270
397
|
* ```
|
|
271
398
|
*/
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (!this.shouldLog('
|
|
399
|
+
debug(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
400
|
+
debug(...args: any[]): void;
|
|
401
|
+
debug(param1: any, ...args: any[]): void {
|
|
402
|
+
if (!this.shouldLog('debug')) return;
|
|
276
403
|
|
|
277
404
|
// Check if first parameter is a valid color key
|
|
278
405
|
if (typeof param1 === 'string' && this.COLORS[param1 as keyof typeof this.COLORS]) {
|
|
279
406
|
console.log(...this.compile(param1 as keyof typeof this.COLORS, ...args));
|
|
280
407
|
} else {
|
|
281
|
-
// Use default
|
|
282
|
-
console.log(...this.compile(
|
|
408
|
+
// Use instance's default log color and treat param1 as first message argument
|
|
409
|
+
console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
|
|
283
410
|
}
|
|
284
411
|
}
|
|
285
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Info logging method with optional color specification
|
|
415
|
+
* Logs without any restrictions (always shows regardless of log level)
|
|
416
|
+
*
|
|
417
|
+
* Supports two usage patterns:
|
|
418
|
+
* 1. info(message, ...args) - Uses instance's default log color
|
|
419
|
+
* 2. info(color, message, ...args) - Uses specified color for message content only
|
|
420
|
+
*
|
|
421
|
+
* Note: The scope color always remains the instance's default scope color,
|
|
422
|
+
* only the message content color changes when explicitly specified.
|
|
423
|
+
*
|
|
424
|
+
* @param color - Optional color key or the first message argument
|
|
425
|
+
* @param args - Additional arguments to log
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* logger.info('Hello World'); // Uses instance default colors
|
|
430
|
+
* logger.info('green', 'Success message'); // Green message, scope stays instance color
|
|
431
|
+
* logger.info('Processing user:', { id: 1, name: 'John' });
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
info(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
435
|
+
info(...args: any[]): void;
|
|
436
|
+
info(param1: any, ...args: any[]): void {
|
|
437
|
+
if (!this.shouldLog('info')) return;
|
|
438
|
+
|
|
439
|
+
// Check if first parameter is a valid color key
|
|
440
|
+
if (typeof param1 === 'string' && this.COLORS[param1 as keyof typeof this.COLORS]) {
|
|
441
|
+
console.log(...this.compile(param1 as keyof typeof this.COLORS, ...args));
|
|
442
|
+
} else {
|
|
443
|
+
// Use instance's default log color and treat param1 as first message argument
|
|
444
|
+
console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Legacy log method (kept for backward compatibility)
|
|
450
|
+
* @deprecated Use info() method instead
|
|
451
|
+
*
|
|
452
|
+
* @param color - Optional color key or the first message argument
|
|
453
|
+
* @param args - Additional arguments to log
|
|
454
|
+
*/
|
|
455
|
+
log(color: keyof typeof this.COLORS, ...args: any[]): void;
|
|
456
|
+
log(...args: any[]): void;
|
|
457
|
+
log(param1: any, ...args: any[]): void {
|
|
458
|
+
// Delegate to info method for backward compatibility
|
|
459
|
+
this.info(param1, ...args);
|
|
460
|
+
}
|
|
461
|
+
|
|
286
462
|
/**
|
|
287
463
|
* Log warning messages with yellow color coding
|
|
288
464
|
*
|
|
@@ -18,17 +18,54 @@ export const A_LOGGER_DEFAULT_LEVEL = 'all';
|
|
|
18
18
|
* Terminal color codes mapping
|
|
19
19
|
*/
|
|
20
20
|
export const A_LOGGER_COLORS = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
// System colors (reserved for specific purposes)
|
|
22
|
+
red: '31', // Errors, critical issues
|
|
23
|
+
yellow: '33', // Warnings, caution messages
|
|
24
|
+
green: '32', // Success, completion messages
|
|
25
|
+
|
|
26
|
+
// Safe palette for random selection (grey-blue-violet theme)
|
|
27
|
+
blue: '34', // Info, general messages
|
|
28
|
+
cyan: '36', // Headers, titles
|
|
29
|
+
magenta: '35', // Special highlighting
|
|
30
|
+
gray: '90', // Debug, less important info
|
|
31
|
+
brightBlue: '94', // Bright blue variant
|
|
32
|
+
brightCyan: '96', // Bright cyan variant
|
|
33
|
+
brightMagenta: '95', // Bright magenta variant
|
|
34
|
+
darkGray: '30', // Dark gray
|
|
35
|
+
lightGray: '37', // Light gray (white)
|
|
36
|
+
|
|
37
|
+
// Extended blue-violet palette
|
|
38
|
+
indigo: '38;5;54', // Deep indigo
|
|
39
|
+
violet: '38;5;93', // Violet
|
|
40
|
+
purple: '38;5;129', // Purple
|
|
41
|
+
lavender: '38;5;183', // Lavender
|
|
42
|
+
skyBlue: '38;5;117', // Sky blue
|
|
43
|
+
steelBlue: '38;5;67', // Steel blue
|
|
44
|
+
slateBlue: '38;5;62', // Slate blue
|
|
45
|
+
deepBlue: '38;5;18', // Deep blue
|
|
46
|
+
lightBlue: '38;5;153', // Light blue
|
|
47
|
+
periwinkle: '38;5;111', // Periwinkle
|
|
48
|
+
cornflower: '38;5;69', // Cornflower blue
|
|
49
|
+
powder: '38;5;152', // Powder blue
|
|
50
|
+
|
|
51
|
+
// Additional grays for variety
|
|
52
|
+
charcoal: '38;5;236', // Charcoal
|
|
53
|
+
silver: '38;5;250', // Silver
|
|
54
|
+
smoke: '38;5;244', // Smoke gray
|
|
55
|
+
slate: '38;5;240', // Slate gray
|
|
30
56
|
} as const;
|
|
31
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Safe colors for random selection - grey-blue-violet palette
|
|
60
|
+
* Excludes system colors (red, yellow, green) to avoid confusion with warnings/errors
|
|
61
|
+
*/
|
|
62
|
+
export const A_LOGGER_SAFE_RANDOM_COLORS = [
|
|
63
|
+
'blue', 'cyan', 'magenta', 'gray', 'brightBlue', 'brightCyan', 'brightMagenta',
|
|
64
|
+
'darkGray', 'lightGray', 'indigo', 'violet', 'purple', 'lavender', 'skyBlue',
|
|
65
|
+
'steelBlue', 'slateBlue', 'deepBlue', 'lightBlue', 'periwinkle', 'cornflower',
|
|
66
|
+
'powder', 'charcoal', 'silver', 'smoke', 'slate'
|
|
67
|
+
] as const;
|
|
68
|
+
|
|
32
69
|
/**
|
|
33
70
|
* ANSI escape codes
|
|
34
71
|
*/
|
|
@@ -65,5 +102,8 @@ export const A_LOGGER_FORMAT = {
|
|
|
65
102
|
* Environment variable keys
|
|
66
103
|
*/
|
|
67
104
|
export const A_LOGGER_ENV_KEYS = {
|
|
68
|
-
LOG_LEVEL: 'A_LOGGER_LEVEL'
|
|
105
|
+
LOG_LEVEL: 'A_LOGGER_LEVEL',
|
|
106
|
+
DEFAULT_SCOPE_LENGTH: 'A_LOGGER_DEFAULT_SCOPE_LENGTH',
|
|
107
|
+
DEFAULT_SCOPE_COLOR: 'A_LOGGER_DEFAULT_SCOPE_COLOR',
|
|
108
|
+
DEFAULT_LOG_COLOR: 'A_LOGGER_DEFAULT_LOG_COLOR'
|
|
69
109
|
} as const;
|
|
@@ -8,19 +8,35 @@ export const A_LoggerEnvVariables = {
|
|
|
8
8
|
*/
|
|
9
9
|
A_LOGGER_LEVEL: 'A_LOGGER_LEVEL',
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
/**
|
|
13
12
|
* Sets the default scope length for log messages
|
|
14
13
|
*
|
|
15
14
|
* @example 'A_LOGGER_DEFAULT_SCOPE_LENGTH'
|
|
16
15
|
*/
|
|
17
16
|
A_LOGGER_DEFAULT_SCOPE_LENGTH: 'A_LOGGER_DEFAULT_SCOPE_LENGTH',
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sets the default color for scope display in log messages
|
|
20
|
+
*
|
|
21
|
+
* @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
|
|
22
|
+
*/
|
|
23
|
+
A_LOGGER_DEFAULT_SCOPE_COLOR: 'A_LOGGER_DEFAULT_SCOPE_COLOR',
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Sets the default color for log message content
|
|
27
|
+
*
|
|
28
|
+
* @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
|
|
29
|
+
*/
|
|
30
|
+
A_LOGGER_DEFAULT_LOG_COLOR: 'A_LOGGER_DEFAULT_LOG_COLOR',
|
|
18
31
|
} as const;
|
|
19
32
|
|
|
20
33
|
|
|
21
34
|
|
|
22
35
|
export const A_LoggerEnvVariablesArray = [
|
|
23
36
|
A_LoggerEnvVariables.A_LOGGER_LEVEL,
|
|
37
|
+
A_LoggerEnvVariables.A_LOGGER_DEFAULT_SCOPE_LENGTH,
|
|
38
|
+
A_LoggerEnvVariables.A_LOGGER_DEFAULT_SCOPE_COLOR,
|
|
39
|
+
A_LoggerEnvVariables.A_LOGGER_DEFAULT_LOG_COLOR,
|
|
24
40
|
] as const;
|
|
25
41
|
|
|
26
42
|
|