traceperf 0.1.0 → 0.1.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.
Files changed (71) hide show
  1. package/README.md +31 -0
  2. package/dist/browser.d.ts +9 -3
  3. package/dist/browser.js +28 -8
  4. package/dist/browser.js.map +1 -1
  5. package/dist/esm/browser.d.ts +73 -0
  6. package/dist/esm/browser.js +275 -0
  7. package/dist/esm/browser.js.map +1 -0
  8. package/dist/esm/core/config.d.ts +77 -0
  9. package/dist/esm/core/config.js +112 -0
  10. package/dist/esm/core/config.js.map +1 -0
  11. package/dist/esm/core/constants.d.ts +78 -0
  12. package/dist/esm/core/constants.js +106 -0
  13. package/dist/esm/core/constants.js.map +1 -0
  14. package/dist/esm/core/index.d.ts +3 -0
  15. package/dist/esm/core/index.js +4 -0
  16. package/dist/esm/core/index.js.map +1 -0
  17. package/dist/esm/core/logger.d.ts +84 -0
  18. package/dist/esm/core/logger.js +170 -0
  19. package/dist/esm/core/logger.js.map +1 -0
  20. package/dist/esm/formatters/ascii.d.ts +52 -0
  21. package/dist/esm/formatters/ascii.js +100 -0
  22. package/dist/esm/formatters/ascii.js.map +1 -0
  23. package/dist/esm/formatters/cli.d.ts +50 -0
  24. package/dist/esm/formatters/cli.js +96 -0
  25. package/dist/esm/formatters/cli.js.map +1 -0
  26. package/dist/esm/formatters/index.d.ts +3 -0
  27. package/dist/esm/formatters/index.js +4 -0
  28. package/dist/esm/formatters/index.js.map +1 -0
  29. package/dist/esm/formatters/json.d.ts +45 -0
  30. package/dist/esm/formatters/json.js +85 -0
  31. package/dist/esm/formatters/json.js.map +1 -0
  32. package/dist/esm/index.d.ts +10 -0
  33. package/dist/esm/index.js +29 -0
  34. package/dist/esm/index.js.map +1 -0
  35. package/dist/esm/trackers/execution.d.ts +72 -0
  36. package/dist/esm/trackers/execution.js +143 -0
  37. package/dist/esm/trackers/execution.js.map +1 -0
  38. package/dist/esm/trackers/index.d.ts +2 -0
  39. package/dist/esm/trackers/index.js +3 -0
  40. package/dist/esm/trackers/index.js.map +1 -0
  41. package/dist/esm/trackers/performance.d.ts +82 -0
  42. package/dist/esm/trackers/performance.js +106 -0
  43. package/dist/esm/trackers/performance.js.map +1 -0
  44. package/dist/esm/types/config.d.ts +110 -0
  45. package/dist/esm/types/config.js +2 -0
  46. package/dist/esm/types/config.js.map +1 -0
  47. package/dist/esm/types/index.d.ts +2 -0
  48. package/dist/esm/types/index.js +3 -0
  49. package/dist/esm/types/index.js.map +1 -0
  50. package/dist/esm/types/logger.d.ts +127 -0
  51. package/dist/esm/types/logger.js +2 -0
  52. package/dist/esm/types/logger.js.map +1 -0
  53. package/dist/esm/utils/colors.d.ts +87 -0
  54. package/dist/esm/utils/colors.js +134 -0
  55. package/dist/esm/utils/colors.js.map +1 -0
  56. package/dist/esm/utils/index.d.ts +3 -0
  57. package/dist/esm/utils/index.js +4 -0
  58. package/dist/esm/utils/index.js.map +1 -0
  59. package/dist/esm/utils/stack.d.ts +63 -0
  60. package/dist/esm/utils/stack.js +110 -0
  61. package/dist/esm/utils/stack.js.map +1 -0
  62. package/dist/esm/utils/timing.d.ts +65 -0
  63. package/dist/esm/utils/timing.js +99 -0
  64. package/dist/esm/utils/timing.js.map +1 -0
  65. package/dist/index.js +13 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/types/config.js +2 -1
  68. package/dist/types/index.js +18 -2
  69. package/dist/types/index.js.map +1 -1
  70. package/dist/types/logger.js +2 -1
  71. package/package.json +16 -2
@@ -0,0 +1,112 @@
1
+ import { DEFAULT_CONFIG, LOG_LEVEL_PRIORITY, MODE_MIN_LEVELS } from './constants';
2
+ /**
3
+ * Configuration manager for the logger
4
+ * Handles merging user config with defaults and provides utility methods
5
+ */
6
+ export class ConfigManager {
7
+ /**
8
+ * Create a new ConfigManager instance
9
+ *
10
+ * @param userConfig - User-provided configuration options
11
+ */
12
+ constructor(userConfig = {}) {
13
+ this._config = { ...DEFAULT_CONFIG, ...userConfig };
14
+ }
15
+ /**
16
+ * Get the current configuration
17
+ *
18
+ * @returns The current configuration
19
+ */
20
+ getConfig() {
21
+ return { ...this._config };
22
+ }
23
+ /**
24
+ * Update the configuration
25
+ *
26
+ * @param newConfig - New configuration options to merge
27
+ */
28
+ updateConfig(newConfig) {
29
+ this._config = { ...this._config, ...newConfig };
30
+ }
31
+ /**
32
+ * Get the current mode
33
+ *
34
+ * @returns The current mode
35
+ */
36
+ getMode() {
37
+ var _a;
38
+ return (_a = this._config.mode) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.mode;
39
+ }
40
+ /**
41
+ * Set the current mode
42
+ *
43
+ * @param mode - The mode to set
44
+ */
45
+ setMode(mode) {
46
+ this._config.mode = mode;
47
+ }
48
+ /**
49
+ * Check if a log level should be displayed based on the current mode and level
50
+ *
51
+ * @param level - The log level to check
52
+ * @returns Whether the log level should be displayed
53
+ */
54
+ shouldLog(level) {
55
+ var _a;
56
+ const currentMode = this.getMode();
57
+ const configLevel = (_a = this._config.level) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.level;
58
+ // Get the minimum level for the current mode
59
+ const modeMinLevel = MODE_MIN_LEVELS[currentMode] || 'info';
60
+ // Use the higher of the mode's minimum level and the configured level
61
+ const effectiveMinLevel = this.getHigherPriorityLevel(modeMinLevel, configLevel);
62
+ // Check if the provided level meets the minimum threshold
63
+ return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[effectiveMinLevel];
64
+ }
65
+ /**
66
+ * Get the higher priority level between two log levels
67
+ *
68
+ * @param levelA - First log level
69
+ * @param levelB - Second log level
70
+ * @returns The higher priority level
71
+ */
72
+ getHigherPriorityLevel(levelA, levelB) {
73
+ return LOG_LEVEL_PRIORITY[levelA] >= LOG_LEVEL_PRIORITY[levelB] ? levelA : levelB;
74
+ }
75
+ /**
76
+ * Get the performance threshold
77
+ *
78
+ * @returns The performance threshold in milliseconds
79
+ */
80
+ getPerformanceThreshold() {
81
+ var _a;
82
+ return (_a = this._config.performanceThreshold) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.performanceThreshold;
83
+ }
84
+ /**
85
+ * Get the indentation size
86
+ *
87
+ * @returns The number of spaces for each indentation level
88
+ */
89
+ getIndentSize() {
90
+ var _a;
91
+ return (_a = this._config.indentSize) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.indentSize;
92
+ }
93
+ /**
94
+ * Check if colorization is enabled
95
+ *
96
+ * @returns Whether colorization is enabled
97
+ */
98
+ isColorEnabled() {
99
+ var _a;
100
+ return (_a = this._config.colorize) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.colorize;
101
+ }
102
+ /**
103
+ * Check if timestamps are enabled
104
+ *
105
+ * @returns Whether timestamps are enabled
106
+ */
107
+ isTimestampEnabled() {
108
+ var _a;
109
+ return (_a = this._config.timestamp) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.timestamp;
110
+ }
111
+ }
112
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAElF;;;GAGG;AACH,MAAM,OAAO,aAAa;IAGxB;;;;OAIG;IACH,YAAY,aAAqC,EAAE;QACjD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,UAAU,EAAE,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,SAAiC;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,EAAE,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,OAAO;;QACZ,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,IAAI,mCAAI,c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AI,CAAC,OAAO,CAAC,SAAS,mCAAI,cAAc,CAAC,SAAoB,CAAC;IACvE,CAAC;CACF"}
@@ -0,0 +1,78 @@
1
+ import { LogLevel, LogMode, ILoggerConfig } from '../types';
2
+ /**
3
+ * Default configuration for the logger
4
+ */
5
+ export declare const DEFAULT_CONFIG: ILoggerConfig;
6
+ /**
7
+ * Log level priorities (higher number = higher priority)
8
+ */
9
+ export declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
10
+ /**
11
+ * Minimum log level for each mode
12
+ */
13
+ export declare const MODE_MIN_LEVELS: Record<LogMode, LogLevel>;
14
+ /**
15
+ * ANSI color codes for terminal output
16
+ */
17
+ export declare const COLORS: {
18
+ reset: string;
19
+ bright: string;
20
+ dim: string;
21
+ underscore: string;
22
+ fg: {
23
+ black: string;
24
+ red: string;
25
+ green: string;
26
+ yellow: string;
27
+ blue: string;
28
+ magenta: string;
29
+ cyan: string;
30
+ white: string;
31
+ gray: string;
32
+ };
33
+ bg: {
34
+ black: string;
35
+ red: string;
36
+ green: string;
37
+ yellow: string;
38
+ blue: string;
39
+ magenta: string;
40
+ cyan: string;
41
+ white: string;
42
+ };
43
+ };
44
+ /**
45
+ * Log level colors
46
+ */
47
+ export declare const LEVEL_COLORS: Record<LogLevel, string>;
48
+ /**
49
+ * Log level icons
50
+ */
51
+ export declare const LEVEL_ICONS: Record<LogLevel, string>;
52
+ /**
53
+ * Box drawing characters for ASCII flow charts
54
+ */
55
+ export declare const BOX_CHARS: {
56
+ topLeft: string;
57
+ topRight: string;
58
+ bottomLeft: string;
59
+ bottomRight: string;
60
+ horizontal: string;
61
+ vertical: string;
62
+ verticalRight: string;
63
+ verticalLeft: string;
64
+ horizontalDown: string;
65
+ horizontalUp: string;
66
+ cross: string;
67
+ downArrow: string;
68
+ };
69
+ /**
70
+ * Performance icons
71
+ */
72
+ export declare const PERFORMANCE_ICONS: {
73
+ timer: string;
74
+ slow: string;
75
+ memory: string;
76
+ bottleneck: string;
77
+ fix: string;
78
+ };
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Default configuration for the logger
3
+ */
4
+ export const DEFAULT_CONFIG = {
5
+ mode: 'dev',
6
+ level: 'debug',
7
+ colorize: true,
8
+ timestamp: true,
9
+ performanceThreshold: 100, // ms
10
+ indentSize: 2,
11
+ };
12
+ /**
13
+ * Log level priorities (higher number = higher priority)
14
+ */
15
+ export const LOG_LEVEL_PRIORITY = {
16
+ debug: 0,
17
+ info: 1,
18
+ warn: 2,
19
+ error: 3,
20
+ };
21
+ /**
22
+ * Minimum log level for each mode
23
+ */
24
+ export const MODE_MIN_LEVELS = {
25
+ dev: 'debug', // In dev mode, show all logs
26
+ staging: 'warn', // In staging, show only warnings and errors
27
+ prod: 'error', // In prod, show only errors
28
+ };
29
+ /**
30
+ * ANSI color codes for terminal output
31
+ */
32
+ export const COLORS = {
33
+ reset: '\x1b[0m',
34
+ bright: '\x1b[1m',
35
+ dim: '\x1b[2m',
36
+ underscore: '\x1b[4m',
37
+ // Foreground colors
38
+ fg: {
39
+ black: '\x1b[30m',
40
+ red: '\x1b[31m',
41
+ green: '\x1b[32m',
42
+ yellow: '\x1b[33m',
43
+ blue: '\x1b[34m',
44
+ magenta: '\x1b[35m',
45
+ cyan: '\x1b[36m',
46
+ white: '\x1b[37m',
47
+ gray: '\x1b[90m',
48
+ },
49
+ // Background colors
50
+ bg: {
51
+ black: '\x1b[40m',
52
+ red: '\x1b[41m',
53
+ green: '\x1b[42m',
54
+ yellow: '\x1b[43m',
55
+ blue: '\x1b[44m',
56
+ magenta: '\x1b[45m',
57
+ cyan: '\x1b[46m',
58
+ white: '\x1b[47m',
59
+ },
60
+ };
61
+ /**
62
+ * Log level colors
63
+ */
64
+ export const LEVEL_COLORS = {
65
+ debug: COLORS.fg.gray,
66
+ info: COLORS.fg.blue,
67
+ warn: COLORS.fg.yellow,
68
+ error: COLORS.fg.red,
69
+ };
70
+ /**
71
+ * Log level icons
72
+ */
73
+ export const LEVEL_ICONS = {
74
+ debug: '🔍',
75
+ info: 'ℹ️',
76
+ warn: '⚠️',
77
+ error: '❌',
78
+ };
79
+ /**
80
+ * Box drawing characters for ASCII flow charts
81
+ */
82
+ export const BOX_CHARS = {
83
+ topLeft: '┌',
84
+ topRight: '┐',
85
+ bottomLeft: '└',
86
+ bottomRight: '┘',
87
+ horizontal: '─',
88
+ vertical: '│',
89
+ verticalRight: '├',
90
+ verticalLeft: '┤',
91
+ horizontalDown: '┬',
92
+ horizontalUp: '┴',
93
+ cross: '┼',
94
+ downArrow: '▼',
95
+ };
96
+ /**
97
+ * Performance icons
98
+ */
99
+ export const PERFORMANCE_ICONS = {
100
+ timer: '⏱',
101
+ slow: '⚠️',
102
+ memory: '📊',
103
+ bottleneck: '🛑',
104
+ fix: '🛠',
105
+ };
106
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/core/constants.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAkB;IAC3C,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,GAAG,EAAE,KAAK;IAChC,UAAU,EAAE,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6B;IAC1D,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA8B;IACxD,GAAG,EAAE,OAAO,EAAK,6BAA6B;IAC9C,OAAO,EAAE,MAAM,EAAG,4CAA4C;IAC9D,IAAI,EAAE,OAAO,EAAK,4BAA4B;CAC/C,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,SAAS;IAChB,MAA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,EAAE,GAAG;IACjB,KAAK,EAAE,GAAG;IACV,SAAS,EAAE,GAAG;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,IAAI;IACZ,UAAU,EAAE,IAAI;IAChB,GAAG,EAAE,IAAI;CACV,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './constants';
3
+ export * from './logger';
@@ -0,0 +1,4 @@
1
+ export * from './config';
2
+ export * from './constants';
3
+ export * from './logger';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { ILogger, ILoggerConfig, LogMode, ITrackOptions } from '../types';
2
+ /**
3
+ * Main logger class that implements the ILogger interface
4
+ */
5
+ export declare class Logger implements ILogger {
6
+ private _config;
7
+ private _executionTracker;
8
+ private _performanceMonitor;
9
+ private _indentLevel;
10
+ private _transports;
11
+ private _formatters;
12
+ /**
13
+ * Create a new Logger instance
14
+ *
15
+ * @param config - Logger configuration
16
+ */
17
+ constructor(config?: Partial<ILoggerConfig>);
18
+ /**
19
+ * Log an informational message
20
+ *
21
+ * @param message - The message to log
22
+ * @param args - Additional arguments to include in the log
23
+ */
24
+ info(message: string | object, ...args: any[]): void;
25
+ /**
26
+ * Log a warning message
27
+ *
28
+ * @param message - The message to log
29
+ * @param args - Additional arguments to include in the log
30
+ */
31
+ warn(message: string | object, ...args: any[]): void;
32
+ /**
33
+ * Log an error message
34
+ *
35
+ * @param message - The message to log
36
+ * @param args - Additional arguments to include in the log
37
+ */
38
+ error(message: string | object, ...args: any[]): void;
39
+ /**
40
+ * Log a debug message
41
+ *
42
+ * @param message - The message to log
43
+ * @param args - Additional arguments to include in the log
44
+ */
45
+ debug(message: string | object, ...args: any[]): void;
46
+ /**
47
+ * Start a new log group with the given label
48
+ *
49
+ * @param label - The label for the group
50
+ */
51
+ group(label: string): void;
52
+ /**
53
+ * End the current log group
54
+ */
55
+ groupEnd(): void;
56
+ /**
57
+ * Set the operational mode for the logger
58
+ *
59
+ * @param mode - The mode to set
60
+ */
61
+ setMode(mode: LogMode): void;
62
+ /**
63
+ * Get the current operational mode
64
+ *
65
+ * @returns The current mode
66
+ */
67
+ getMode(): LogMode;
68
+ /**
69
+ * Track the execution of a function and log performance metrics
70
+ *
71
+ * @param fn - The function to track
72
+ * @param options - Options for tracking
73
+ * @returns The return value of the tracked function
74
+ */
75
+ track<T>(fn: () => T, options?: ITrackOptions): T;
76
+ /**
77
+ * Internal method to log a message
78
+ *
79
+ * @param level - The log level
80
+ * @param message - The message to log
81
+ * @param args - Additional arguments
82
+ */
83
+ private log;
84
+ }
@@ -0,0 +1,170 @@
1
+ import { ConfigManager } from './config';
2
+ import { ExecutionTracker } from '../trackers/execution';
3
+ import { PerformanceMonitor } from '../trackers/performance';
4
+ import { CliFormatter } from '../formatters/cli';
5
+ /**
6
+ * Console transport for outputting logs to the console
7
+ */
8
+ class ConsoleTransport {
9
+ /**
10
+ * Write a log entry to the console
11
+ *
12
+ * @param entry - The formatted log entry
13
+ */
14
+ write(entry) {
15
+ console.log(entry);
16
+ }
17
+ }
18
+ /**
19
+ * Main logger class that implements the ILogger interface
20
+ */
21
+ export class Logger {
22
+ /**
23
+ * Create a new Logger instance
24
+ *
25
+ * @param config - Logger configuration
26
+ */
27
+ constructor(config = {}) {
28
+ this._indentLevel = 0;
29
+ this._config = new ConfigManager(config);
30
+ // Set up trackers
31
+ this._executionTracker = new ExecutionTracker({
32
+ defaultThreshold: this._config.getPerformanceThreshold(),
33
+ });
34
+ this._performanceMonitor = new PerformanceMonitor({
35
+ defaultThreshold: this._config.getPerformanceThreshold(),
36
+ });
37
+ // Set up transports
38
+ this._transports = config.transports || [new ConsoleTransport()];
39
+ // Set up formatters
40
+ this._formatters = config.formatters || [
41
+ new CliFormatter({
42
+ colorEnabled: this._config.isColorEnabled(),
43
+ indentSize: this._config.getIndentSize(),
44
+ }),
45
+ ];
46
+ }
47
+ /**
48
+ * Log an informational message
49
+ *
50
+ * @param message - The message to log
51
+ * @param args - Additional arguments to include in the log
52
+ */
53
+ info(message, ...args) {
54
+ this.log('info', message, args);
55
+ }
56
+ /**
57
+ * Log a warning message
58
+ *
59
+ * @param message - The message to log
60
+ * @param args - Additional arguments to include in the log
61
+ */
62
+ warn(message, ...args) {
63
+ this.log('warn', message, args);
64
+ }
65
+ /**
66
+ * Log an error message
67
+ *
68
+ * @param message - The message to log
69
+ * @param args - Additional arguments to include in the log
70
+ */
71
+ error(message, ...args) {
72
+ this.log('error', message, args);
73
+ }
74
+ /**
75
+ * Log a debug message
76
+ *
77
+ * @param message - The message to log
78
+ * @param args - Additional arguments to include in the log
79
+ */
80
+ debug(message, ...args) {
81
+ // Skip debug logs in production mode
82
+ if (this.getMode() === 'prod') {
83
+ return;
84
+ }
85
+ this.log('debug', message, args);
86
+ }
87
+ /**
88
+ * Start a new log group with the given label
89
+ *
90
+ * @param label - The label for the group
91
+ */
92
+ group(label) {
93
+ this.info(label);
94
+ this._indentLevel++;
95
+ }
96
+ /**
97
+ * End the current log group
98
+ */
99
+ groupEnd() {
100
+ if (this._indentLevel > 0) {
101
+ this._indentLevel--;
102
+ }
103
+ }
104
+ /**
105
+ * Set the operational mode for the logger
106
+ *
107
+ * @param mode - The mode to set
108
+ */
109
+ setMode(mode) {
110
+ this._config.setMode(mode);
111
+ }
112
+ /**
113
+ * Get the current operational mode
114
+ *
115
+ * @returns The current mode
116
+ */
117
+ getMode() {
118
+ return this._config.getMode();
119
+ }
120
+ /**
121
+ * Track the execution of a function and log performance metrics
122
+ *
123
+ * @param fn - The function to track
124
+ * @param options - Options for tracking
125
+ * @returns The return value of the tracked function
126
+ */
127
+ track(fn, options) {
128
+ var _a;
129
+ const silent = (_a = options === null || options === void 0 ? void 0 : options.silent) !== null && _a !== void 0 ? _a : false;
130
+ // Track the function execution
131
+ const result = this._executionTracker.track(fn, options);
132
+ // Log the execution flow if not silent
133
+ if (!silent) {
134
+ const flowChart = this._executionTracker.generateFlowChart();
135
+ // Log the flow chart directly to the console
136
+ // This bypasses the formatters to preserve the ASCII art
137
+ console.log('\nExecution Flow:');
138
+ console.log(flowChart);
139
+ }
140
+ return result;
141
+ }
142
+ /**
143
+ * Internal method to log a message
144
+ *
145
+ * @param level - The log level
146
+ * @param message - The message to log
147
+ * @param args - Additional arguments
148
+ */
149
+ log(level, message, args) {
150
+ // Check if this log level should be displayed
151
+ if (!this._config.shouldLog(level)) {
152
+ return;
153
+ }
154
+ // Create metadata for the log entry
155
+ const meta = {
156
+ timestamp: new Date(),
157
+ level,
158
+ indentLevel: this._indentLevel,
159
+ };
160
+ // Format the log entry using each formatter
161
+ for (const formatter of this._formatters) {
162
+ const formattedEntry = formatter.format(level, message, args, meta);
163
+ // Send to each transport
164
+ for (const transport of this._transports) {
165
+ transport.write(formattedEntry);
166
+ }
167
+ }
168
+ }
169
+ }
170
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/core/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,MAAM,gBAAgB;IACpB;;;;OAIG;IACI,KAAK,CAAC,KAAa;QACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,MAAM;IAQjB;;;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IACK,GAAG,CAAC,KAAe,EAAE,OAAwB,EAAE,IAAW;QAChE,8CAA8C;QAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,oCAAoC;QACpC,MAAM,IAAI,GAAY;YACpB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,KAAK;YACL,WAAW,EAAE,IAAI,CAAC,YAAY;SAC/B,CAAC;QAEF,4CAA4C;QAC5C,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YAEpE,yBAAyB;YACzB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACzC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Execution data for a function call
3
+ */
4
+ export interface ExecutionData {
5
+ name: string;
6
+ duration: number;
7
+ isSlow: boolean;
8
+ memoryUsage?: number;
9
+ level: number;
10
+ }
11
+ /**
12
+ * ASCII art generator for execution flow charts
13
+ */
14
+ export declare class AsciiArtGenerator {
15
+ private _boxWidth;
16
+ /**
17
+ * Create a new AsciiArtGenerator instance
18
+ *
19
+ * @param options - Generator options
20
+ */
21
+ constructor(options?: {
22
+ boxWidth?: number;
23
+ });
24
+ /**
25
+ * Generate a flow chart for a sequence of function executions
26
+ *
27
+ * @param executions - Array of execution data
28
+ * @returns ASCII art flow chart
29
+ */
30
+ generateFlowChart(executions: ExecutionData[]): string;
31
+ /**
32
+ * Generate a box for a function execution
33
+ *
34
+ * @param execution - The execution data
35
+ * @returns ASCII art box
36
+ */
37
+ private generateFunctionBox;
38
+ /**
39
+ * Generate an arrow between function boxes
40
+ *
41
+ * @param levelDiff - Difference in nesting level
42
+ * @returns ASCII art arrow
43
+ */
44
+ private generateArrow;
45
+ /**
46
+ * Format memory usage in a human-readable format
47
+ *
48
+ * @param bytes - Memory usage in bytes
49
+ * @returns Formatted memory usage
50
+ */
51
+ private formatMemory;
52
+ }