@adaas/a-utils 0.2.9 → 0.3.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.
@@ -1,776 +0,0 @@
1
- import { A_Config } from './chunk-RLXT47QH.mjs';
2
- import { __decorateClass, __decorateParam } from './chunk-EQQGB2QZ.mjs';
3
- import { A_Inject, A_Scope, A_Component, A_Context, A_Error } from '@adaas/a-concept';
4
- import { A_Frame } from '@adaas/a-frame';
5
-
6
- // src/lib/A-Logger/A-Logger.constants.ts
7
- var A_LOGGER_DEFAULT_SCOPE_LENGTH = 20;
8
- var A_LOGGER_DEFAULT_LEVEL = "all";
9
- var A_LOGGER_COLORS = {
10
- // System colors (reserved for specific purposes)
11
- red: "31",
12
- // Errors, critical issues
13
- yellow: "33",
14
- // Warnings, caution messages
15
- green: "32",
16
- // Success, completion messages
17
- // Safe palette for random selection (grey-blue-violet theme)
18
- blue: "34",
19
- // Info, general messages
20
- cyan: "36",
21
- // Headers, titles
22
- magenta: "35",
23
- // Special highlighting
24
- gray: "90",
25
- // Debug, less important info
26
- brightBlue: "94",
27
- // Bright blue variant
28
- brightCyan: "96",
29
- // Bright cyan variant
30
- brightMagenta: "95",
31
- // Bright magenta variant
32
- darkGray: "30",
33
- // Dark gray
34
- lightGray: "37",
35
- // Light gray (white)
36
- // Extended blue-violet palette
37
- indigo: "38;5;54",
38
- // Deep indigo
39
- violet: "38;5;93",
40
- // Violet
41
- purple: "38;5;129",
42
- // Purple
43
- lavender: "38;5;183",
44
- // Lavender
45
- skyBlue: "38;5;117",
46
- // Sky blue
47
- steelBlue: "38;5;67",
48
- // Steel blue
49
- slateBlue: "38;5;62",
50
- // Slate blue
51
- deepBlue: "38;5;18",
52
- // Deep blue
53
- lightBlue: "38;5;153",
54
- // Light blue
55
- periwinkle: "38;5;111",
56
- // Periwinkle
57
- cornflower: "38;5;69",
58
- // Cornflower blue
59
- powder: "38;5;152",
60
- // Powder blue
61
- // Additional grays for variety
62
- charcoal: "38;5;236",
63
- // Charcoal
64
- silver: "38;5;250",
65
- // Silver
66
- smoke: "38;5;244",
67
- // Smoke gray
68
- slate: "38;5;240"
69
- // Slate gray
70
- };
71
- var A_LOGGER_SAFE_RANDOM_COLORS = [
72
- "blue",
73
- "cyan",
74
- "magenta",
75
- "gray",
76
- "brightBlue",
77
- "brightCyan",
78
- "brightMagenta",
79
- "darkGray",
80
- "lightGray",
81
- "indigo",
82
- "violet",
83
- "purple",
84
- "lavender",
85
- "skyBlue",
86
- "steelBlue",
87
- "slateBlue",
88
- "deepBlue",
89
- "lightBlue",
90
- "periwinkle",
91
- "cornflower",
92
- "powder",
93
- "charcoal",
94
- "silver",
95
- "smoke",
96
- "slate"
97
- ];
98
- var A_LOGGER_ANSI = {
99
- RESET: "\x1B[0m",
100
- PREFIX: "\x1B[",
101
- SUFFIX: "m"
102
- };
103
- var A_LOGGER_TIME_FORMAT = {
104
- MINUTES_PAD: 2,
105
- SECONDS_PAD: 2,
106
- MILLISECONDS_PAD: 3,
107
- SEPARATOR: ":"
108
- };
109
- var A_LOGGER_FORMAT = {
110
- SCOPE_OPEN: "[",
111
- SCOPE_CLOSE: "]",
112
- TIME_OPEN: "|",
113
- TIME_CLOSE: "|",
114
- SEPARATOR: "-------------------------------",
115
- INDENT_BASE: 3,
116
- PIPE: "| "
117
- };
118
- var A_LOGGER_TERMINAL = {
119
- DEFAULT_WIDTH: 80,
120
- // Default terminal width when can't be detected
121
- MIN_WIDTH: 40,
122
- // Minimum width for formatted output
123
- MAX_LINE_LENGTH_RATIO: 0.8,
124
- // Use 80% of terminal width for content
125
- BROWSER_DEFAULT_WIDTH: 120
126
- // Default width for browser console
127
- };
128
- var A_LOGGER_ENV_KEYS = {
129
- LOG_LEVEL: "A_LOGGER_LEVEL",
130
- DEFAULT_SCOPE_LENGTH: "A_LOGGER_DEFAULT_SCOPE_LENGTH",
131
- DEFAULT_SCOPE_COLOR: "A_LOGGER_DEFAULT_SCOPE_COLOR",
132
- DEFAULT_LOG_COLOR: "A_LOGGER_DEFAULT_LOG_COLOR"
133
- };
134
- var A_Logger = class extends A_Component {
135
- // =============================================
136
- // Constructor and Initialization
137
- // =============================
138
- /**
139
- * Initialize A_Logger with dependency injection
140
- * Colors are configured through A_Config or generated randomly if not provided
141
- *
142
- * @param scope - The current scope context for message prefixing
143
- * @param config - Optional configuration for log level filtering and color settings
144
- */
145
- constructor(scope, config) {
146
- super();
147
- this.scope = scope;
148
- this.config = config;
149
- this.COLORS = A_LOGGER_COLORS;
150
- this.STANDARD_SCOPE_LENGTH = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_LENGTH) || A_LOGGER_DEFAULT_SCOPE_LENGTH;
151
- const configScopeColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_COLOR);
152
- const configLogColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_LOG_COLOR);
153
- if (configScopeColor || configLogColor) {
154
- this.DEFAULT_SCOPE_COLOR = configScopeColor || this.generateColorFromScopeName(this.scope.name);
155
- this.DEFAULT_LOG_COLOR = configLogColor || this.generateColorFromScopeName(this.scope.name);
156
- } else {
157
- const complementaryColors = this.generateComplementaryColorsFromScope(this.scope.name);
158
- this.DEFAULT_SCOPE_COLOR = complementaryColors.scopeColor;
159
- this.DEFAULT_LOG_COLOR = complementaryColors.logColor;
160
- }
161
- this.TERMINAL_WIDTH = this.detectTerminalWidth();
162
- this.MAX_CONTENT_WIDTH = Math.floor(this.TERMINAL_WIDTH * A_LOGGER_TERMINAL.MAX_LINE_LENGTH_RATIO);
163
- }
164
- // =============================================
165
- // Color Generation Utilities
166
- // =============================================
167
- /**
168
- * Generate a simple hash from a string
169
- * Used to create deterministic color selection based on scope name
170
- *
171
- * @param str - The string to hash
172
- * @returns A numeric hash value
173
- */
174
- simpleHash(str) {
175
- let hash = 0;
176
- for (let i = 0; i < str.length; i++) {
177
- const char = str.charCodeAt(i);
178
- hash = (hash << 5) - hash + char;
179
- hash = hash & hash;
180
- }
181
- return Math.abs(hash);
182
- }
183
- /**
184
- * Generate a deterministic color based on scope name
185
- * Same scope names will always get the same color, but uses safe color palette
186
- *
187
- * @param scopeName - The scope name to generate color for
188
- * @returns A color key from the safe colors palette
189
- */
190
- generateColorFromScopeName(scopeName) {
191
- const safeColors = A_LOGGER_SAFE_RANDOM_COLORS;
192
- const hash = this.simpleHash(scopeName);
193
- const colorIndex = hash % safeColors.length;
194
- return safeColors[colorIndex];
195
- }
196
- /**
197
- * Generate a pair of complementary colors based on scope name
198
- * Ensures visual harmony between scope and message colors while being deterministic
199
- *
200
- * @param scopeName - The scope name to base colors on
201
- * @returns Object with scopeColor and logColor that work well together
202
- */
203
- generateComplementaryColorsFromScope(scopeName) {
204
- const colorPairs = [
205
- { scopeColor: "indigo", logColor: "lightBlue" },
206
- { scopeColor: "deepBlue", logColor: "cyan" },
207
- { scopeColor: "purple", logColor: "lavender" },
208
- { scopeColor: "steelBlue", logColor: "skyBlue" },
209
- { scopeColor: "slateBlue", logColor: "periwinkle" },
210
- { scopeColor: "charcoal", logColor: "silver" },
211
- { scopeColor: "violet", logColor: "brightMagenta" },
212
- { scopeColor: "darkGray", logColor: "lightGray" },
213
- { scopeColor: "cornflower", logColor: "powder" },
214
- { scopeColor: "slate", logColor: "smoke" }
215
- ];
216
- const hash = this.simpleHash(scopeName);
217
- const pairIndex = hash % colorPairs.length;
218
- return colorPairs[pairIndex];
219
- }
220
- // =============================================
221
- // Terminal Width Detection
222
- // =============================================
223
- /**
224
- * Detect current terminal width based on environment
225
- *
226
- * Returns appropriate width for different environments:
227
- * - Node.js: Uses process.stdout.columns if available
228
- * - Browser: Returns browser default width
229
- * - Fallback: Returns default terminal width
230
- *
231
- * @returns Terminal width in characters
232
- */
233
- detectTerminalWidth() {
234
- try {
235
- if (A_Context.environment === "browser") {
236
- return A_LOGGER_TERMINAL.BROWSER_DEFAULT_WIDTH;
237
- }
238
- if (typeof process !== "undefined" && process.stdout && process.stdout.columns) {
239
- const cols = process.stdout.columns;
240
- return Math.max(cols, A_LOGGER_TERMINAL.MIN_WIDTH);
241
- }
242
- return A_LOGGER_TERMINAL.DEFAULT_WIDTH;
243
- } catch (error) {
244
- return A_LOGGER_TERMINAL.DEFAULT_WIDTH;
245
- }
246
- }
247
- /**
248
- * Wrap text to fit within terminal width while preserving formatting
249
- *
250
- * @param text - Text to wrap
251
- * @param scopePadding - The scope padding string for alignment
252
- * @param isFirstLine - Whether this is the first line (affects available width calculation)
253
- * @returns Array of wrapped lines with proper indentation
254
- */
255
- wrapText(text, scopePadding, isFirstLine = true) {
256
- if (A_Context.environment === "browser") {
257
- return [text];
258
- }
259
- const scopeHeaderLength = this.formattedScope.length + 4 + this.getTime().length + 4;
260
- const continuationIndent = `${scopePadding}${A_LOGGER_FORMAT.PIPE}`;
261
- const firstLineMaxWidth = Math.max(this.TERMINAL_WIDTH - scopeHeaderLength - 1, 20);
262
- const continuationMaxWidth = Math.max(this.TERMINAL_WIDTH - continuationIndent.length, 20);
263
- if (isFirstLine && text.length <= firstLineMaxWidth) {
264
- return [text];
265
- }
266
- const lines = [];
267
- const words = text.split(" ");
268
- let currentLine = "";
269
- let currentMaxWidth = isFirstLine ? firstLineMaxWidth : continuationMaxWidth;
270
- for (const word of words) {
271
- const spaceNeeded = currentLine ? 1 : 0;
272
- const totalLength = currentLine.length + spaceNeeded + word.length;
273
- if (totalLength > currentMaxWidth) {
274
- if (currentLine) {
275
- lines.push(currentLine);
276
- currentLine = word;
277
- currentMaxWidth = continuationMaxWidth;
278
- } else {
279
- if (word.length > currentMaxWidth) {
280
- const chunks = this.splitLongWord(word, currentMaxWidth);
281
- lines.push(...chunks.slice(0, -1));
282
- currentLine = chunks[chunks.length - 1];
283
- } else {
284
- currentLine = word;
285
- }
286
- currentMaxWidth = continuationMaxWidth;
287
- }
288
- } else {
289
- currentLine += (currentLine ? " " : "") + word;
290
- }
291
- }
292
- if (currentLine) {
293
- lines.push(currentLine);
294
- }
295
- return lines.length ? lines : [text];
296
- }
297
- /**
298
- * Split a long word that doesn't fit on a single line
299
- *
300
- * @param word - Word to split
301
- * @param maxLength - Maximum length per chunk
302
- * @returns Array of word chunks
303
- */
304
- splitLongWord(word, maxLength) {
305
- const chunks = [];
306
- for (let i = 0; i < word.length; i += maxLength) {
307
- chunks.push(word.slice(i, i + maxLength));
308
- }
309
- return chunks;
310
- }
311
- // =============================================
312
- // Factory Methods
313
- // =============================
314
- // =============================================
315
- // Scope and Formatting Utilities
316
- // =============================================
317
- /**
318
- * Get the formatted scope length for consistent message alignment
319
- * Uses a standard length to ensure all messages align properly regardless of scope name
320
- *
321
- * @returns The scope length to use for padding calculations
322
- */
323
- get scopeLength() {
324
- return Math.max(this.scope.name.length, this.STANDARD_SCOPE_LENGTH);
325
- }
326
- /**
327
- * Get the formatted scope name with proper padding, centered within the container
328
- * Ensures consistent width for all scope names in log output with centered alignment
329
- *
330
- * @returns Centered and padded scope name for consistent formatting
331
- */
332
- get formattedScope() {
333
- const scopeName = this.scope.name;
334
- const totalLength = this.STANDARD_SCOPE_LENGTH;
335
- if (scopeName.length >= totalLength) {
336
- return scopeName.substring(0, totalLength);
337
- }
338
- const totalPadding = totalLength - scopeName.length;
339
- const leftPadding = Math.floor(totalPadding / 2);
340
- const rightPadding = totalPadding - leftPadding;
341
- return " ".repeat(leftPadding) + scopeName + " ".repeat(rightPadding);
342
- }
343
- // =============================================
344
- // Message Compilation and Formatting
345
- // =============================================
346
- /**
347
- * Compile log arguments into formatted console output with colors and proper alignment
348
- *
349
- * This method handles the core formatting logic for all log messages:
350
- * - Applies separate colors for scope and message content
351
- * - Formats scope names with consistent padding
352
- * - Handles different data types appropriately
353
- * - Maintains proper indentation for multi-line content
354
- *
355
- * @param messageColor - The color key to apply to the message content
356
- * @param args - Variable arguments to format and display
357
- * @returns Array of formatted strings and/or objects ready for console output
358
- */
359
- compile(messageColor, ...args) {
360
- const timeString = this.getTime();
361
- const scopePadding = " ".repeat(this.STANDARD_SCOPE_LENGTH + 3);
362
- const isMultiArg = args.length > 1;
363
- return [
364
- // Header with separate colors for scope and message content
365
- `${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}`,
366
- // Top separator for multi-argument messages
367
- isMultiArg ? `
368
- ${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}` : "",
369
- // Process each argument with appropriate formatting
370
- ...args.map((arg, i) => {
371
- const shouldAddNewline = i > 0 || isMultiArg;
372
- switch (true) {
373
- case arg instanceof A_Error:
374
- return this.compile_A_Error(arg);
375
- case arg instanceof Error:
376
- return this.compile_Error(arg);
377
- case (typeof arg === "object" && arg !== null):
378
- return this.formatObject(arg, shouldAddNewline, scopePadding);
379
- default:
380
- return this.formatString(String(arg), shouldAddNewline, scopePadding);
381
- }
382
- }),
383
- // Bottom separator and color reset
384
- isMultiArg ? `
385
- ${scopePadding}${A_LOGGER_FORMAT.TIME_OPEN}${A_LOGGER_FORMAT.SEPARATOR}${A_LOGGER_ANSI.RESET}` : A_LOGGER_ANSI.RESET
386
- ];
387
- }
388
- /**
389
- * Format an object for display with proper JSON indentation and terminal width awareness
390
- *
391
- * @param obj - The object to format
392
- * @param shouldAddNewline - Whether to add a newline prefix
393
- * @param scopePadding - The padding string for consistent alignment
394
- * @returns Formatted object string or the object itself for browser environments
395
- */
396
- formatObject(obj, shouldAddNewline, scopePadding) {
397
- if (A_Context.environment === "browser") {
398
- return obj;
399
- }
400
- if (obj === null) {
401
- return shouldAddNewline ? `
402
- ${scopePadding}${A_LOGGER_FORMAT.PIPE}null` : "null";
403
- }
404
- if (obj === void 0) {
405
- return shouldAddNewline ? `
406
- ${scopePadding}${A_LOGGER_FORMAT.PIPE}undefined` : "undefined";
407
- }
408
- let jsonString;
409
- try {
410
- jsonString = JSON.stringify(obj, null, 2);
411
- } catch (error) {
412
- try {
413
- const seen = /* @__PURE__ */ new WeakSet();
414
- jsonString = JSON.stringify(obj, (key, value) => {
415
- if (typeof value === "object" && value !== null) {
416
- if (seen.has(value)) {
417
- return "[Circular Reference]";
418
- }
419
- seen.add(value);
420
- }
421
- return value;
422
- }, 2);
423
- } catch (fallbackError) {
424
- jsonString = String(obj);
425
- }
426
- }
427
- const continuationIndent = `${scopePadding}${A_LOGGER_FORMAT.PIPE}`;
428
- const maxJsonLineWidth = this.TERMINAL_WIDTH - continuationIndent.length - 4;
429
- const lines = jsonString.split("\n").map((line) => {
430
- const stringValueMatch = line.match(/^(\s*"[^"]+":\s*")([^"]+)(".*)?$/);
431
- if (stringValueMatch && stringValueMatch[2].length > maxJsonLineWidth - stringValueMatch[1].length - (stringValueMatch[3] || "").length) {
432
- const [, prefix, value, suffix = ""] = stringValueMatch;
433
- if (value.length > maxJsonLineWidth - prefix.length - suffix.length) {
434
- const wrappedValue = this.wrapJsonStringValue(value, maxJsonLineWidth - prefix.length - suffix.length);
435
- return prefix + wrappedValue + suffix;
436
- }
437
- }
438
- return line;
439
- });
440
- const formatted = lines.join("\n" + continuationIndent);
441
- return shouldAddNewline ? "\n" + continuationIndent + formatted : formatted;
442
- }
443
- /**
444
- * Wrap a long JSON string value while preserving readability
445
- *
446
- * @param value - The string value to wrap
447
- * @param maxWidth - Maximum width for the value
448
- * @returns Wrapped string value
449
- */
450
- wrapJsonStringValue(value, maxWidth) {
451
- if (value.length <= maxWidth) {
452
- return value;
453
- }
454
- if (maxWidth > 6) {
455
- return value.substring(0, maxWidth - 3) + "...";
456
- } else {
457
- return value.substring(0, Math.max(1, maxWidth));
458
- }
459
- }
460
- /**
461
- * Format a string for display with proper indentation and terminal width wrapping
462
- *
463
- * @param str - The string to format
464
- * @param shouldAddNewline - Whether to add a newline prefix
465
- * @param scopePadding - The padding string for consistent alignment
466
- * @returns Formatted string
467
- */
468
- formatString(str, shouldAddNewline, scopePadding) {
469
- if (A_Context.environment === "browser") {
470
- const prefix = shouldAddNewline ? "\n" : "";
471
- return (prefix + str).replace(/\n/g, `
472
- ${scopePadding}${A_LOGGER_FORMAT.PIPE}`);
473
- }
474
- const wrappedLines = this.wrapText(str, scopePadding, !shouldAddNewline);
475
- const continuationIndent = `${scopePadding}${A_LOGGER_FORMAT.PIPE}`;
476
- const formattedLines = wrappedLines.map((line, index) => {
477
- if (index === 0 && !shouldAddNewline) {
478
- return line;
479
- } else {
480
- return `${continuationIndent}${line}`;
481
- }
482
- });
483
- if (shouldAddNewline) {
484
- return "\n" + formattedLines.join("\n");
485
- } else {
486
- return formattedLines.join("\n");
487
- }
488
- }
489
- // =============================================
490
- // Log Level Management
491
- // =============================================
492
- /**
493
- * Determine if a log message should be output based on configured log level
494
- *
495
- * Log level hierarchy:
496
- * - debug: Shows all messages (debug, info, warning, error)
497
- * - info: Shows info, warning, and error messages
498
- * - warn: Shows warning and error messages only
499
- * - error: Shows error messages only
500
- * - all: Shows all messages (alias for debug)
501
- *
502
- * @param logMethod - The type of log method being called
503
- * @returns True if the message should be logged, false otherwise
504
- */
505
- shouldLog(logMethod) {
506
- const shouldLog = this.config?.get(A_LOGGER_ENV_KEYS.LOG_LEVEL) || "info";
507
- switch (shouldLog) {
508
- case "debug":
509
- return true;
510
- case "info":
511
- return logMethod === "info" || logMethod === "warning" || logMethod === "error";
512
- case "warn":
513
- return logMethod === "warning" || logMethod === "error";
514
- case "error":
515
- return logMethod === "error";
516
- case "all":
517
- return true;
518
- default:
519
- return false;
520
- }
521
- }
522
- debug(param1, ...args) {
523
- if (!this.shouldLog("debug")) return;
524
- if (typeof param1 === "string" && this.COLORS[param1]) {
525
- console.log(...this.compile(param1, ...args));
526
- } else {
527
- console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
528
- }
529
- }
530
- info(param1, ...args) {
531
- if (!this.shouldLog("info")) return;
532
- if (typeof param1 === "string" && this.COLORS[param1]) {
533
- console.log(...this.compile(param1, ...args));
534
- } else {
535
- console.log(...this.compile(this.DEFAULT_LOG_COLOR, param1, ...args));
536
- }
537
- }
538
- log(param1, ...args) {
539
- this.info(param1, ...args);
540
- }
541
- /**
542
- * Log warning messages with yellow color coding
543
- *
544
- * Use for non-critical issues that should be brought to attention
545
- * but don't prevent normal operation
546
- *
547
- * @param args - Arguments to log as warnings
548
- *
549
- * @example
550
- * ```typescript
551
- * logger.warning('Deprecated method used');
552
- * logger.warning('Rate limit approaching:', { current: 95, limit: 100 });
553
- * ```
554
- */
555
- warning(...args) {
556
- if (!this.shouldLog("warning")) return;
557
- console.log(...this.compile("yellow", ...args));
558
- }
559
- /**
560
- * Log error messages with red color coding
561
- *
562
- * Use for critical issues, exceptions, and failures that need immediate attention
563
- *
564
- * @param args - Arguments to log as errors
565
- * @returns void (for compatibility with console.log)
566
- *
567
- * @example
568
- * ```typescript
569
- * logger.error('Database connection failed');
570
- * logger.error(new Error('Validation failed'));
571
- * logger.error('Critical error:', error, { context: 'user-registration' });
572
- * ```
573
- */
574
- error(...args) {
575
- if (!this.shouldLog("error")) return;
576
- console.log(...this.compile("red", ...args));
577
- }
578
- // =============================================
579
- // Specialized Error Formatting
580
- // =============================================
581
- /**
582
- * Legacy method for A_Error logging (kept for backward compatibility)
583
- *
584
- * @deprecated Use error() method instead which handles A_Error automatically
585
- * @param error - The A_Error instance to log
586
- */
587
- log_A_Error(error) {
588
- const time = this.getTime();
589
- const scopePadding = " ".repeat(this.STANDARD_SCOPE_LENGTH + 3);
590
- console.log(`\x1B[31m[${this.formattedScope}] |${time}| ERROR ${error.code}
591
- ${scopePadding}| ${error.message}
592
- ${scopePadding}| ${error.description}
593
- ${scopePadding}|-------------------------------
594
- ${scopePadding}| ${error.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
595
- ${scopePadding}|-------------------------------
596
- \x1B[0m` + (error.originalError ? `\x1B[31m${scopePadding}| Wrapped From ${error.originalError.message}
597
- ${scopePadding}|-------------------------------
598
- ${scopePadding}| ${error.originalError.stack?.split("\n").map((line, index) => index === 0 ? line : `${scopePadding}| ${line}`).join("\n") || "No stack trace"}
599
- ${scopePadding}|-------------------------------
600
- \x1B[0m` : "") + (error.link ? `\x1B[31m${scopePadding}| Read in docs: ${error.link}
601
- ${scopePadding}|-------------------------------
602
- \x1B[0m` : ""));
603
- }
604
- /**
605
- * Format A_Error instances for inline display within compiled messages
606
- *
607
- * Provides detailed formatting for A_Error objects with:
608
- * - Error code, message, and description
609
- * - Original error information FIRST (better UX for debugging)
610
- * - Stack traces with terminal width awareness
611
- * - Documentation links (if available)
612
- * - Consistent formatting with rest of logger
613
- *
614
- * @param error - The A_Error instance to format
615
- * @returns Formatted string ready for display
616
- */
617
- compile_A_Error(error) {
618
- const continuationIndent = `${" ".repeat(this.STANDARD_SCOPE_LENGTH + 3)}${A_LOGGER_FORMAT.PIPE}`;
619
- const separator = `${continuationIndent}-------------------------------`;
620
- const lines = [];
621
- lines.push("");
622
- lines.push(separator);
623
- lines.push(`${continuationIndent}A_ERROR: ${error.code}`);
624
- lines.push(separator);
625
- const errorMessage = this.wrapText(`Message: ${error.message}`, continuationIndent, false);
626
- const errorDescription = this.wrapText(`Description: ${error.description}`, continuationIndent, false);
627
- lines.push(...errorMessage.map((line) => `${continuationIndent}${line}`));
628
- lines.push(...errorDescription.map((line) => `${continuationIndent}${line}`));
629
- if (error.originalError) {
630
- lines.push(separator);
631
- lines.push(`${continuationIndent}ORIGINAL ERROR:`);
632
- lines.push(separator);
633
- const originalMessage = this.wrapText(`${error.originalError.name}: ${error.originalError.message}`, continuationIndent, false);
634
- lines.push(...originalMessage.map((line) => `${continuationIndent}${line}`));
635
- if (error.originalError.stack) {
636
- lines.push(`${continuationIndent}Stack trace:`);
637
- const stackLines = this.formatStackTrace(error.originalError.stack, continuationIndent);
638
- lines.push(...stackLines);
639
- }
640
- }
641
- if (error.stack) {
642
- lines.push(separator);
643
- lines.push(`${continuationIndent}A_ERROR STACK:`);
644
- lines.push(separator);
645
- const stackLines = this.formatStackTrace(error.stack, continuationIndent);
646
- lines.push(...stackLines);
647
- }
648
- if (error.link) {
649
- lines.push(separator);
650
- const linkText = this.wrapText(`Documentation: ${error.link}`, continuationIndent, false);
651
- lines.push(...linkText.map((line) => `${continuationIndent}${line}`));
652
- }
653
- lines.push(separator);
654
- return lines.join("\n");
655
- }
656
- /**
657
- * Format stack trace with proper terminal width wrapping and indentation
658
- *
659
- * @param stack - The stack trace string
660
- * @param baseIndent - Base indentation for continuation lines
661
- * @returns Array of formatted stack trace lines
662
- */
663
- formatStackTrace(stack, baseIndent) {
664
- const stackLines = stack.split("\n");
665
- const formatted = [];
666
- stackLines.forEach((line, index) => {
667
- if (line.trim()) {
668
- const stackIndent = index === 0 ? baseIndent : `${baseIndent} `;
669
- const wrappedLines = this.wrapText(line.trim(), stackIndent, false);
670
- formatted.push(...wrappedLines.map(
671
- (wrappedLine) => index === 0 && wrappedLine === wrappedLines[0] ? `${baseIndent}${wrappedLine}` : `${baseIndent} ${wrappedLine}`
672
- ));
673
- }
674
- });
675
- return formatted;
676
- }
677
- /**
678
- * Format standard Error instances for inline display within compiled messages
679
- *
680
- * Provides clean, readable formatting for standard JavaScript errors with:
681
- * - Terminal width aware message wrapping
682
- * - Properly formatted stack traces
683
- * - Consistent indentation with rest of logger
684
- *
685
- * @param error - The Error instance to format
686
- * @returns Formatted string ready for display
687
- */
688
- compile_Error(error) {
689
- const continuationIndent = `${" ".repeat(this.STANDARD_SCOPE_LENGTH + 3)}${A_LOGGER_FORMAT.PIPE}`;
690
- const separator = `${continuationIndent}-------------------------------`;
691
- const lines = [];
692
- lines.push("");
693
- lines.push(separator);
694
- lines.push(`${continuationIndent}ERROR: ${error.name}`);
695
- lines.push(separator);
696
- const errorMessage = this.wrapText(`Message: ${error.message}`, continuationIndent, false);
697
- lines.push(...errorMessage.map((line) => `${continuationIndent}${line}`));
698
- if (error.stack) {
699
- lines.push(separator);
700
- lines.push(`${continuationIndent}STACK TRACE:`);
701
- lines.push(separator);
702
- const stackLines = this.formatStackTrace(error.stack, continuationIndent);
703
- lines.push(...stackLines);
704
- }
705
- lines.push(separator);
706
- return lines.join("\n");
707
- }
708
- // =============================================
709
- // Utility Methods
710
- // =============================================
711
- /**
712
- * Generate timestamp string for log messages
713
- *
714
- * Format: MM:SS:mmm (minutes:seconds:milliseconds)
715
- * This provides sufficient precision for debugging while remaining readable
716
- *
717
- * @returns Formatted timestamp string
718
- *
719
- * @example
720
- * Returns: "15:42:137" for 3:42:15 PM and 137 milliseconds
721
- */
722
- getTime() {
723
- const now = /* @__PURE__ */ new Date();
724
- const minutes = String(now.getMinutes()).padStart(A_LOGGER_TIME_FORMAT.MINUTES_PAD, "0");
725
- const seconds = String(now.getSeconds()).padStart(A_LOGGER_TIME_FORMAT.SECONDS_PAD, "0");
726
- const milliseconds = String(now.getMilliseconds()).padStart(A_LOGGER_TIME_FORMAT.MILLISECONDS_PAD, "0");
727
- return `${minutes}${A_LOGGER_TIME_FORMAT.SEPARATOR}${seconds}${A_LOGGER_TIME_FORMAT.SEPARATOR}${milliseconds}`;
728
- }
729
- };
730
- A_Logger = __decorateClass([
731
- A_Frame.Component({
732
- namespace: "A-Utils",
733
- name: "A_Logger",
734
- description: "Advanced Logging Component with Scope-based Output Formatting that provides color-coded console output, multi-type support, and configurable log levels for enhanced debugging and monitoring."
735
- }),
736
- __decorateParam(0, A_Inject(A_Scope)),
737
- __decorateParam(1, A_Inject(A_Config))
738
- ], A_Logger);
739
-
740
- // src/lib/A-Logger/A-Logger.env.ts
741
- var A_LoggerEnvVariables = {
742
- /**
743
- * Sets the log level for the logger
744
- *
745
- * @example 'debug', 'info', 'warn', 'error'
746
- */
747
- A_LOGGER_LEVEL: "A_LOGGER_LEVEL",
748
- /**
749
- * Sets the default scope length for log messages
750
- *
751
- * @example 'A_LOGGER_DEFAULT_SCOPE_LENGTH'
752
- */
753
- A_LOGGER_DEFAULT_SCOPE_LENGTH: "A_LOGGER_DEFAULT_SCOPE_LENGTH",
754
- /**
755
- * Sets the default color for scope display in log messages
756
- *
757
- * @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
758
- */
759
- A_LOGGER_DEFAULT_SCOPE_COLOR: "A_LOGGER_DEFAULT_SCOPE_COLOR",
760
- /**
761
- * Sets the default color for log message content
762
- *
763
- * @example 'green', 'blue', 'red', 'yellow', 'gray', 'magenta', 'cyan', 'white', 'pink'
764
- */
765
- A_LOGGER_DEFAULT_LOG_COLOR: "A_LOGGER_DEFAULT_LOG_COLOR"
766
- };
767
- var A_LoggerEnvVariablesArray = [
768
- A_LoggerEnvVariables.A_LOGGER_LEVEL,
769
- A_LoggerEnvVariables.A_LOGGER_DEFAULT_SCOPE_LENGTH,
770
- A_LoggerEnvVariables.A_LOGGER_DEFAULT_SCOPE_COLOR,
771
- A_LoggerEnvVariables.A_LOGGER_DEFAULT_LOG_COLOR
772
- ];
773
-
774
- export { A_LOGGER_ANSI, A_LOGGER_COLORS, A_LOGGER_DEFAULT_LEVEL, A_LOGGER_DEFAULT_SCOPE_LENGTH, A_LOGGER_ENV_KEYS, A_LOGGER_FORMAT, A_LOGGER_SAFE_RANDOM_COLORS, A_LOGGER_TERMINAL, A_LOGGER_TIME_FORMAT, A_Logger, A_LoggerEnvVariables, A_LoggerEnvVariablesArray };
775
- //# sourceMappingURL=chunk-HWSDIXPG.mjs.map
776
- //# sourceMappingURL=chunk-HWSDIXPG.mjs.map