traceperf 0.1.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/dist/browser.d.ts +67 -0
  4. package/dist/browser.js +260 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/core/config.d.ts +77 -0
  7. package/dist/core/config.js +116 -0
  8. package/dist/core/config.js.map +1 -0
  9. package/dist/core/constants.d.ts +78 -0
  10. package/dist/core/constants.js +109 -0
  11. package/dist/core/constants.js.map +1 -0
  12. package/dist/core/index.d.ts +3 -0
  13. package/dist/core/index.js +20 -0
  14. package/dist/core/index.js.map +1 -0
  15. package/dist/core/logger.d.ts +84 -0
  16. package/dist/core/logger.js +174 -0
  17. package/dist/core/logger.js.map +1 -0
  18. package/dist/formatters/ascii.d.ts +52 -0
  19. package/dist/formatters/ascii.js +104 -0
  20. package/dist/formatters/ascii.js.map +1 -0
  21. package/dist/formatters/cli.d.ts +50 -0
  22. package/dist/formatters/cli.js +100 -0
  23. package/dist/formatters/cli.js.map +1 -0
  24. package/dist/formatters/index.d.ts +3 -0
  25. package/dist/formatters/index.js +20 -0
  26. package/dist/formatters/index.js.map +1 -0
  27. package/dist/formatters/json.d.ts +45 -0
  28. package/dist/formatters/json.js +89 -0
  29. package/dist/formatters/json.js.map +1 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +33 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/trackers/execution.d.ts +72 -0
  34. package/dist/trackers/execution.js +147 -0
  35. package/dist/trackers/execution.js.map +1 -0
  36. package/dist/trackers/index.d.ts +2 -0
  37. package/dist/trackers/index.js +19 -0
  38. package/dist/trackers/index.js.map +1 -0
  39. package/dist/trackers/performance.d.ts +82 -0
  40. package/dist/trackers/performance.js +110 -0
  41. package/dist/trackers/performance.js.map +1 -0
  42. package/dist/types/config.d.ts +110 -0
  43. package/dist/types/config.js +2 -0
  44. package/dist/types/config.js.map +1 -0
  45. package/dist/types/index.d.ts +2 -0
  46. package/dist/types/index.js +3 -0
  47. package/dist/types/index.js.map +1 -0
  48. package/dist/types/logger.d.ts +127 -0
  49. package/dist/types/logger.js +2 -0
  50. package/dist/types/logger.js.map +1 -0
  51. package/dist/utils/colors.d.ts +87 -0
  52. package/dist/utils/colors.js +148 -0
  53. package/dist/utils/colors.js.map +1 -0
  54. package/dist/utils/index.d.ts +3 -0
  55. package/dist/utils/index.js +20 -0
  56. package/dist/utils/index.js.map +1 -0
  57. package/dist/utils/stack.d.ts +63 -0
  58. package/dist/utils/stack.js +116 -0
  59. package/dist/utils/stack.js.map +1 -0
  60. package/dist/utils/timing.d.ts +65 -0
  61. package/dist/utils/timing.js +106 -0
  62. package/dist/utils/timing.js.map +1 -0
  63. package/package.json +62 -0
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigManager = void 0;
4
+ const constants_1 = require("./constants");
5
+ /**
6
+ * Configuration manager for the logger
7
+ * Handles merging user config with defaults and provides utility methods
8
+ */
9
+ class ConfigManager {
10
+ /**
11
+ * Create a new ConfigManager instance
12
+ *
13
+ * @param userConfig - User-provided configuration options
14
+ */
15
+ constructor(userConfig = {}) {
16
+ this._config = { ...constants_1.DEFAULT_CONFIG, ...userConfig };
17
+ }
18
+ /**
19
+ * Get the current configuration
20
+ *
21
+ * @returns The current configuration
22
+ */
23
+ getConfig() {
24
+ return { ...this._config };
25
+ }
26
+ /**
27
+ * Update the configuration
28
+ *
29
+ * @param newConfig - New configuration options to merge
30
+ */
31
+ updateConfig(newConfig) {
32
+ this._config = { ...this._config, ...newConfig };
33
+ }
34
+ /**
35
+ * Get the current mode
36
+ *
37
+ * @returns The current mode
38
+ */
39
+ getMode() {
40
+ var _a;
41
+ return (_a = this._config.mode) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.mode;
42
+ }
43
+ /**
44
+ * Set the current mode
45
+ *
46
+ * @param mode - The mode to set
47
+ */
48
+ setMode(mode) {
49
+ this._config.mode = mode;
50
+ }
51
+ /**
52
+ * Check if a log level should be displayed based on the current mode and level
53
+ *
54
+ * @param level - The log level to check
55
+ * @returns Whether the log level should be displayed
56
+ */
57
+ shouldLog(level) {
58
+ var _a;
59
+ const currentMode = this.getMode();
60
+ const configLevel = (_a = this._config.level) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.level;
61
+ // Get the minimum level for the current mode
62
+ const modeMinLevel = constants_1.MODE_MIN_LEVELS[currentMode] || 'info';
63
+ // Use the higher of the mode's minimum level and the configured level
64
+ const effectiveMinLevel = this.getHigherPriorityLevel(modeMinLevel, configLevel);
65
+ // Check if the provided level meets the minimum threshold
66
+ return constants_1.LOG_LEVEL_PRIORITY[level] >= constants_1.LOG_LEVEL_PRIORITY[effectiveMinLevel];
67
+ }
68
+ /**
69
+ * Get the higher priority level between two log levels
70
+ *
71
+ * @param levelA - First log level
72
+ * @param levelB - Second log level
73
+ * @returns The higher priority level
74
+ */
75
+ getHigherPriorityLevel(levelA, levelB) {
76
+ return constants_1.LOG_LEVEL_PRIORITY[levelA] >= constants_1.LOG_LEVEL_PRIORITY[levelB] ? levelA : levelB;
77
+ }
78
+ /**
79
+ * Get the performance threshold
80
+ *
81
+ * @returns The performance threshold in milliseconds
82
+ */
83
+ getPerformanceThreshold() {
84
+ var _a;
85
+ return (_a = this._config.performanceThreshold) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.performanceThreshold;
86
+ }
87
+ /**
88
+ * Get the indentation size
89
+ *
90
+ * @returns The number of spaces for each indentation level
91
+ */
92
+ getIndentSize() {
93
+ var _a;
94
+ return (_a = this._config.indentSize) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.indentSize;
95
+ }
96
+ /**
97
+ * Check if colorization is enabled
98
+ *
99
+ * @returns Whether colorization is enabled
100
+ */
101
+ isColorEnabled() {
102
+ var _a;
103
+ return (_a = this._config.colorize) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.colorize;
104
+ }
105
+ /**
106
+ * Check if timestamps are enabled
107
+ *
108
+ * @returns Whether timestamps are enabled
109
+ */
110
+ isTimestampEnabled() {
111
+ var _a;
112
+ return (_a = this._config.timestamp) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_CONFIG.timestamp;
113
+ }
114
+ }
115
+ exports.ConfigManager = ConfigManager;
116
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":";;;AACA,2CAAkF;AAElF;;;GAGG;AACH,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,aAAqC,EAAE;QACjD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,0BAAc,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,0BAAc,CAAC,IAAe,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,IAAa;QAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,KAAe;;QAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACnC,MAAM,WAAW,GAAG,MAAA,IAAI,CAAC,OAAO,CAAC,KAAK,mCAAI,0BAAc,CAAC,KAAiB,CAAC;QAE3E,6CAA6C;QAC7C,MAAM,YAAY,GAAG,2BAAe,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC;QAE5D,sEAAsE;QACtE,MAAM,iBAAiB,GAAG,IAAI,CAAC,sBAAsB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QAEjF,0DAA0D;QAC1D,OAAO,8BAAkB,CAAC,KAAK,CAAC,IAAI,8BAAkB,CAAC,iBAAiB,CAAC,CAAC;IAC5E,CAAC;IAED;;;;;;OAMG;IACK,sBAAsB,CAAC,MAAgB,EAAE,MAAgB;QAC/D,OAAO,8BAAkB,CAAC,MAAM,CAAC,IAAI,8BAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACI,uBAAuB;;QAC5B,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,oBAAoB,mCAAI,0BAAc,CAAC,oBAA8B,CAAC;IAC5F,CAAC;IAED;;;;OAIG;IACI,aAAa;;QAClB,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,UAAU,mCAAI,0BAAc,CAAC,UAAoB,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,cAAc;;QACnB,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,mCAAI,0BAAc,CAAC,QAAmB,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACI,kBAAkB;;QACvB,OAAO,MAAA,IAAI,CAAC,OAAO,CAAC,SAAS,mCAAI,0BAAc,CAAC,SAAoB,CAAC;IACvE,CAAC;CACF;AAlHD,sCAkHC"}
@@ -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,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PERFORMANCE_ICONS = exports.BOX_CHARS = exports.LEVEL_ICONS = exports.LEVEL_COLORS = exports.COLORS = exports.MODE_MIN_LEVELS = exports.LOG_LEVEL_PRIORITY = exports.DEFAULT_CONFIG = void 0;
4
+ /**
5
+ * Default configuration for the logger
6
+ */
7
+ exports.DEFAULT_CONFIG = {
8
+ mode: 'dev',
9
+ level: 'debug',
10
+ colorize: true,
11
+ timestamp: true,
12
+ performanceThreshold: 100, // ms
13
+ indentSize: 2,
14
+ };
15
+ /**
16
+ * Log level priorities (higher number = higher priority)
17
+ */
18
+ exports.LOG_LEVEL_PRIORITY = {
19
+ debug: 0,
20
+ info: 1,
21
+ warn: 2,
22
+ error: 3,
23
+ };
24
+ /**
25
+ * Minimum log level for each mode
26
+ */
27
+ exports.MODE_MIN_LEVELS = {
28
+ dev: 'debug', // In dev mode, show all logs
29
+ staging: 'warn', // In staging, show only warnings and errors
30
+ prod: 'error', // In prod, show only errors
31
+ };
32
+ /**
33
+ * ANSI color codes for terminal output
34
+ */
35
+ exports.COLORS = {
36
+ reset: '\x1b[0m',
37
+ bright: '\x1b[1m',
38
+ dim: '\x1b[2m',
39
+ underscore: '\x1b[4m',
40
+ // Foreground colors
41
+ fg: {
42
+ black: '\x1b[30m',
43
+ red: '\x1b[31m',
44
+ green: '\x1b[32m',
45
+ yellow: '\x1b[33m',
46
+ blue: '\x1b[34m',
47
+ magenta: '\x1b[35m',
48
+ cyan: '\x1b[36m',
49
+ white: '\x1b[37m',
50
+ gray: '\x1b[90m',
51
+ },
52
+ // Background colors
53
+ bg: {
54
+ black: '\x1b[40m',
55
+ red: '\x1b[41m',
56
+ green: '\x1b[42m',
57
+ yellow: '\x1b[43m',
58
+ blue: '\x1b[44m',
59
+ magenta: '\x1b[45m',
60
+ cyan: '\x1b[46m',
61
+ white: '\x1b[47m',
62
+ },
63
+ };
64
+ /**
65
+ * Log level colors
66
+ */
67
+ exports.LEVEL_COLORS = {
68
+ debug: exports.COLORS.fg.gray,
69
+ info: exports.COLORS.fg.blue,
70
+ warn: exports.COLORS.fg.yellow,
71
+ error: exports.COLORS.fg.red,
72
+ };
73
+ /**
74
+ * Log level icons
75
+ */
76
+ exports.LEVEL_ICONS = {
77
+ debug: '🔍',
78
+ info: 'ℹ️',
79
+ warn: '⚠️',
80
+ error: '❌',
81
+ };
82
+ /**
83
+ * Box drawing characters for ASCII flow charts
84
+ */
85
+ exports.BOX_CHARS = {
86
+ topLeft: '┌',
87
+ topRight: '┐',
88
+ bottomLeft: '└',
89
+ bottomRight: '┘',
90
+ horizontal: '─',
91
+ vertical: '│',
92
+ verticalRight: '├',
93
+ verticalLeft: '┤',
94
+ horizontalDown: '┬',
95
+ horizontalUp: '┴',
96
+ cross: '┼',
97
+ downArrow: '▼',
98
+ };
99
+ /**
100
+ * Performance icons
101
+ */
102
+ exports.PERFORMANCE_ICONS = {
103
+ timer: '⏱',
104
+ slow: '⚠️',
105
+ memory: '📊',
106
+ bottleneck: '🛑',
107
+ fix: '🛠',
108
+ };
109
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/core/constants.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACU,QAAA,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;AACU,QAAA,kBAAkB,GAA6B;IAC1D,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;GAEG;AACU,QAAA,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;AACU,QAAA,MAAM,GAAG;IACpB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,GAAG,EAAE,SAAS;IACd,UAAU,EAAE,SAAS;IAErB,oBAAoB;IACpB,EAAE,EAAE;QACF,KAAK,EAAE,UAAU;QACjB,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,UA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E,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,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config"), exports);
18
+ __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./logger"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB"}
@@ -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,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ const config_1 = require("./config");
5
+ const execution_1 = require("../trackers/execution");
6
+ const performance_1 = require("../trackers/performance");
7
+ const cli_1 = require("../formatters/cli");
8
+ /**
9
+ * Console transport for outputting logs to the console
10
+ */
11
+ class ConsoleTransport {
12
+ /**
13
+ * Write a log entry to the console
14
+ *
15
+ * @param entry - The formatted log entry
16
+ */
17
+ write(entry) {
18
+ console.log(entry);
19
+ }
20
+ }
21
+ /**
22
+ * Main logger class that implements the ILogger interface
23
+ */
24
+ class Logger {
25
+ /**
26
+ * Create a new Logger instance
27
+ *
28
+ * @param config - Logger configuration
29
+ */
30
+ constructor(config = {}) {
31
+ this._indentLevel = 0;
32
+ this._config = new config_1.ConfigManager(config);
33
+ // Set up trackers
34
+ this._executionTracker = new execution_1.ExecutionTracker({
35
+ defaultThreshold: this._config.getPerformanceThreshold(),
36
+ });
37
+ this._performanceMonitor = new performance_1.PerformanceMonitor({
38
+ defaultThreshold: this._config.getPerformanceThreshold(),
39
+ });
40
+ // Set up transports
41
+ this._transports = config.transports || [new ConsoleTransport()];
42
+ // Set up formatters
43
+ this._formatters = config.formatters || [
44
+ new cli_1.CliFormatter({
45
+ colorEnabled: this._config.isColorEnabled(),
46
+ indentSize: this._config.getIndentSize(),
47
+ }),
48
+ ];
49
+ }
50
+ /**
51
+ * Log an informational message
52
+ *
53
+ * @param message - The message to log
54
+ * @param args - Additional arguments to include in the log
55
+ */
56
+ info(message, ...args) {
57
+ this.log('info', message, args);
58
+ }
59
+ /**
60
+ * Log a warning message
61
+ *
62
+ * @param message - The message to log
63
+ * @param args - Additional arguments to include in the log
64
+ */
65
+ warn(message, ...args) {
66
+ this.log('warn', message, args);
67
+ }
68
+ /**
69
+ * Log an error message
70
+ *
71
+ * @param message - The message to log
72
+ * @param args - Additional arguments to include in the log
73
+ */
74
+ error(message, ...args) {
75
+ this.log('error', message, args);
76
+ }
77
+ /**
78
+ * Log a debug message
79
+ *
80
+ * @param message - The message to log
81
+ * @param args - Additional arguments to include in the log
82
+ */
83
+ debug(message, ...args) {
84
+ // Skip debug logs in production mode
85
+ if (this.getMode() === 'prod') {
86
+ return;
87
+ }
88
+ this.log('debug', message, args);
89
+ }
90
+ /**
91
+ * Start a new log group with the given label
92
+ *
93
+ * @param label - The label for the group
94
+ */
95
+ group(label) {
96
+ this.info(label);
97
+ this._indentLevel++;
98
+ }
99
+ /**
100
+ * End the current log group
101
+ */
102
+ groupEnd() {
103
+ if (this._indentLevel > 0) {
104
+ this._indentLevel--;
105
+ }
106
+ }
107
+ /**
108
+ * Set the operational mode for the logger
109
+ *
110
+ * @param mode - The mode to set
111
+ */
112
+ setMode(mode) {
113
+ this._config.setMode(mode);
114
+ }
115
+ /**
116
+ * Get the current operational mode
117
+ *
118
+ * @returns The current mode
119
+ */
120
+ getMode() {
121
+ return this._config.getMode();
122
+ }
123
+ /**
124
+ * Track the execution of a function and log performance metrics
125
+ *
126
+ * @param fn - The function to track
127
+ * @param options - Options for tracking
128
+ * @returns The return value of the tracked function
129
+ */
130
+ track(fn, options) {
131
+ var _a;
132
+ const silent = (_a = options === null || options === void 0 ? void 0 : options.silent) !== null && _a !== void 0 ? _a : false;
133
+ // Track the function execution
134
+ const result = this._executionTracker.track(fn, options);
135
+ // Log the execution flow if not silent
136
+ if (!silent) {
137
+ const flowChart = this._executionTracker.generateFlowChart();
138
+ // Log the flow chart directly to the console
139
+ // This bypasses the formatters to preserve the ASCII art
140
+ console.log('\nExecution Flow:');
141
+ console.log(flowChart);
142
+ }
143
+ return result;
144
+ }
145
+ /**
146
+ * Internal method to log a message
147
+ *
148
+ * @param level - The log level
149
+ * @param message - The message to log
150
+ * @param args - Additional arguments
151
+ */
152
+ log(level, message, args) {
153
+ // Check if this log level should be displayed
154
+ if (!this._config.shouldLog(level)) {
155
+ return;
156
+ }
157
+ // Create metadata for the log entry
158
+ const meta = {
159
+ timestamp: new Date(),
160
+ level,
161
+ indentLevel: this._indentLevel,
162
+ };
163
+ // Format the log entry using each formatter
164
+ for (const formatter of this._formatters) {
165
+ const formattedEntry = formatter.format(level, message, args, meta);
166
+ // Send to each transport
167
+ for (const transport of this._transports) {
168
+ transport.write(formattedEntry);
169
+ }
170
+ }
171
+ }
172
+ }
173
+ exports.Logger = Logger;
174
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,qCA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BAAiB,CAAC,iBAAiB,EAAE,CAAC;YAE7D,6CAA6C;YAC7C,yDAAyD;YACzD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;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;AA/KD,wBA+KC"}
@@ -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
+ }