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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 TracePerf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # TracePerf
2
+
3
+ Advanced console logging & performance tracking for Node.js applications.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/traceperf.svg)](https://www.npmjs.com/package/traceperf)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Features
9
+
10
+ - **Structured and Visually Appealing Logs**: A better alternative to `console.log()` with colors, icons, and formatting.
11
+ - **Execution Flow Tracing**: Track function calls and visualize the execution flow with ASCII art.
12
+ - **Performance Bottleneck Detection**: Identify slow functions and get suggestions for optimization.
13
+ - **Conditional Logging Modes**: Different logging levels for development, staging, and production.
14
+ - **Nested Logging**: Group related logs with indentation for better readability.
15
+ - **Auto-Remove Debug Logs**: Automatically filter out debug logs in production.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install traceperf
21
+ ```
22
+
23
+ ## Basic Usage
24
+
25
+ ```javascript
26
+ const tracePerf = require('traceperf');
27
+
28
+ // Basic logging
29
+ tracePerf.info('This is an info message');
30
+ tracePerf.warn('This is a warning message');
31
+ tracePerf.error('This is an error message');
32
+ tracePerf.debug('This is a debug message');
33
+
34
+ // Logging with objects
35
+ tracePerf.info('User data:', { id: 1, name: 'John Doe' });
36
+
37
+ // Nested logging with groups
38
+ tracePerf.group('User Authentication');
39
+ tracePerf.info('Checking credentials');
40
+ tracePerf.warn('Invalid password attempt');
41
+ tracePerf.groupEnd();
42
+ ```
43
+
44
+ ## Execution Flow Tracking
45
+
46
+ ```javascript
47
+ function fetchData() {
48
+ processData();
49
+ }
50
+
51
+ function processData() {
52
+ calculateResults();
53
+ }
54
+
55
+ function calculateResults() {
56
+ return 'done';
57
+ }
58
+
59
+ // Track the execution of the fetchData function
60
+ const result = tracePerf.track(fetchData);
61
+ ```
62
+
63
+ Output:
64
+
65
+ ```
66
+ Execution Flow:
67
+ ┌──────────────────────────────┐
68
+ │ fetchData │ ⏱ 200ms
69
+ └──────────────────────────────┘
70
+ │
71
+ ▼
72
+ ┌──────────────────────────────┐
73
+ │ processData │ ⏱ 500ms ⚠️ SLOW
74
+ └──────────────────────────────┘
75
+ │
76
+ ▼
77
+ ┌──────────────────────────────┐
78
+ │ calculateResults │ ⏱ 300ms
79
+ └──────────────────────────────┘
80
+ ```
81
+
82
+ ## Conditional Logging Modes
83
+
84
+ ```javascript
85
+ // Development mode (default)
86
+ tracePerf.setMode('dev');
87
+ tracePerf.debug('Debug message'); // Shown
88
+ tracePerf.info('Info message'); // Shown
89
+ tracePerf.warn('Warning message'); // Shown
90
+ tracePerf.error('Error message'); // Shown
91
+
92
+ // Staging mode
93
+ tracePerf.setMode('staging');
94
+ tracePerf.debug('Debug message'); // Not shown
95
+ tracePerf.info('Info message'); // Not shown
96
+ tracePerf.warn('Warning message'); // Shown
97
+ tracePerf.error('Error message'); // Shown
98
+
99
+ // Production mode
100
+ tracePerf.setMode('prod');
101
+ tracePerf.debug('Debug message'); // Not shown
102
+ tracePerf.info('Info message'); // Not shown
103
+ tracePerf.warn('Warning message'); // Not shown
104
+ tracePerf.error('Error message'); // Shown
105
+ ```
106
+
107
+ ## Browser Usage (React, Next.js, etc.)
108
+
109
+ TracePerf also provides a browser-compatible version for use in frontend applications:
110
+
111
+ ```javascript
112
+ // Import the browser version
113
+ import tracePerf from 'traceperf/browser';
114
+
115
+ // Use it just like the Node.js version
116
+ tracePerf.info('This works in the browser!');
117
+
118
+ // Track function performance
119
+ function expensiveCalculation() {
120
+ // ...complex logic
121
+ return result;
122
+ }
123
+
124
+ const result = tracePerf.track(expensiveCalculation);
125
+ ```
126
+
127
+ ### React Component Example
128
+
129
+ ```jsx
130
+ import React, { useEffect } from 'react';
131
+ import tracePerf from 'traceperf/browser';
132
+
133
+ function DataComponent() {
134
+ useEffect(() => {
135
+ tracePerf.group('Component Lifecycle');
136
+ tracePerf.info('Component mounted');
137
+
138
+ // Fetch data with performance tracking
139
+ tracePerf.track(async () => {
140
+ const data = await fetchData();
141
+ // Process data...
142
+ }, { label: 'fetchAndProcessData', threshold: 300 });
143
+
144
+ return () => {
145
+ tracePerf.info('Component unmounting');
146
+ tracePerf.groupEnd();
147
+ };
148
+ }, []);
149
+
150
+ // Component rendering...
151
+ }
152
+ ```
153
+
154
+ ## Advanced Configuration
155
+
156
+ ```javascript
157
+ const { createLogger } = require('traceperf');
158
+
159
+ // Create a custom logger instance
160
+ const logger = createLogger({
161
+ mode: 'dev',
162
+ level: 'debug',
163
+ colorize: true,
164
+ timestamp: true,
165
+ performanceThreshold: 100, // ms
166
+ indentSize: 2,
167
+ });
168
+
169
+ // Use the custom logger
170
+ logger.info('Custom logger');
171
+ ```
172
+
173
+ ## API Reference
174
+
175
+ ### Logging Methods
176
+
177
+ - `info(message, ...args)`: Log an informational message
178
+ - `warn(message, ...args)`: Log a warning message
179
+ - `error(message, ...args)`: Log an error message
180
+ - `debug(message, ...args)`: Log a debug message (filtered in production)
181
+
182
+ ### Grouping
183
+
184
+ - `group(label)`: Start a new log group with the given label
185
+ - `groupEnd()`: End the current log group
186
+
187
+ ### Execution Tracking
188
+
189
+ - `track(fn, options)`: Track the execution of a function and log performance metrics
190
+ - `options.label`: Custom label for the tracked function
191
+ - `options.threshold`: Performance threshold in milliseconds
192
+ - `options.includeMemory`: Whether to include memory usage tracking
193
+ - `options.silent`: Whether to suppress logging for this tracking
194
+
195
+ ### Configuration
196
+
197
+ - `setMode(mode)`: Set the operational mode ('dev', 'staging', 'prod')
198
+ - `getMode()`: Get the current operational mode
199
+
200
+ ## License
201
+
202
+ MIT
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Browser-compatible version of TracePerf
3
+ *
4
+ * This file provides a browser-compatible version of TracePerf that can be used
5
+ * in React, Next.js, or other frontend applications.
6
+ */
7
+ import { ILoggerConfig, LogMode, ITrackOptions } from './types';
8
+ /**
9
+ * Browser-compatible performance monitoring
10
+ */
11
+ declare class BrowserPerformanceMonitor {
12
+ private _timers;
13
+ private _defaultThreshold;
14
+ constructor(options?: {
15
+ defaultThreshold?: number;
16
+ });
17
+ startTimer(label: string): string;
18
+ endTimer(id: string): number;
19
+ isBottleneck(duration: number, threshold?: number): boolean;
20
+ getMemoryUsage(): {
21
+ heapUsed: number;
22
+ heapTotal: number;
23
+ external: number;
24
+ rss: number;
25
+ };
26
+ generateSuggestion(functionName: string, duration: number, memoryUsage?: number): string;
27
+ }
28
+ /**
29
+ * Browser-compatible execution tracker
30
+ */
31
+ declare class BrowserExecutionTracker {
32
+ private _callStack;
33
+ private _executions;
34
+ private _currentExecution;
35
+ private _defaultThreshold;
36
+ constructor(options?: {
37
+ defaultThreshold?: number;
38
+ });
39
+ track<T>(fn: () => T, options?: ITrackOptions): T;
40
+ getCallStack(): string[];
41
+ generateFlowChart(): string;
42
+ clear(): void;
43
+ }
44
+ /**
45
+ * Browser-compatible logger
46
+ */
47
+ declare class BrowserLogger {
48
+ private _mode;
49
+ private _indentLevel;
50
+ private _executionTracker;
51
+ private _performanceMonitor;
52
+ constructor(config?: Partial<ILoggerConfig>);
53
+ info(message: string | object, ...args: any[]): void;
54
+ warn(message: string | object, ...args: any[]): void;
55
+ error(message: string | object, ...args: any[]): void;
56
+ debug(message: string | object, ...args: any[]): void;
57
+ group(label: string): void;
58
+ groupEnd(): void;
59
+ setMode(mode: LogMode): void;
60
+ getMode(): LogMode;
61
+ track<T>(fn: () => T, options?: ITrackOptions): T;
62
+ private log;
63
+ }
64
+ declare const browserLogger: BrowserLogger;
65
+ export default browserLogger;
66
+ export declare function createBrowserLogger(config?: Partial<ILoggerConfig>): BrowserLogger;
67
+ export { BrowserLogger, BrowserExecutionTracker, BrowserPerformanceMonitor };
@@ -0,0 +1,260 @@
1
+ /**
2
+ * Browser-compatible version of TracePerf
3
+ *
4
+ * This file provides a browser-compatible version of TracePerf that can be used
5
+ * in React, Next.js, or other frontend applications.
6
+ */
7
+ /**
8
+ * Browser-compatible performance monitoring
9
+ */
10
+ class BrowserPerformanceMonitor {
11
+ constructor(options = {}) {
12
+ var _a;
13
+ this._timers = new Map();
14
+ this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
15
+ }
16
+ startTimer(label) {
17
+ const id = `${label}-${Math.random().toString(36).substring(2, 9)}`;
18
+ this._timers.set(id, performance.now());
19
+ return id;
20
+ }
21
+ endTimer(id) {
22
+ const startTime = this._timers.get(id);
23
+ if (!startTime) {
24
+ throw new Error(`Timer with id ${id} not found`);
25
+ }
26
+ const duration = performance.now() - startTime;
27
+ this._timers.delete(id);
28
+ return duration;
29
+ }
30
+ isBottleneck(duration, threshold) {
31
+ const effectiveThreshold = threshold !== null && threshold !== void 0 ? threshold : this._defaultThreshold;
32
+ return duration > effectiveThreshold;
33
+ }
34
+ getMemoryUsage() {
35
+ // Use browser performance API if available
36
+ if (performance && 'memory' in performance) {
37
+ const memory = performance.memory;
38
+ return {
39
+ heapUsed: (memory === null || memory === void 0 ? void 0 : memory.usedJSHeapSize) || 0,
40
+ heapTotal: (memory === null || memory === void 0 ? void 0 : memory.totalJSHeapSize) || 0,
41
+ external: 0, // Not available in browser
42
+ rss: 0, // Not available in browser
43
+ };
44
+ }
45
+ // Fallback for browsers without memory API
46
+ return {
47
+ heapUsed: 0,
48
+ heapTotal: 0,
49
+ external: 0,
50
+ rss: 0,
51
+ };
52
+ }
53
+ generateSuggestion(functionName, duration, memoryUsage) {
54
+ if (duration > 1000) {
55
+ return `🛠 Potential Fix: Consider optimizing or adding caching to ${functionName}`;
56
+ }
57
+ if (duration > 500) {
58
+ return `🛠 Potential Fix: Look for blocking operations in ${functionName}`;
59
+ }
60
+ return `🛠 Potential Fix: Review ${functionName} for performance optimizations`;
61
+ }
62
+ }
63
+ /**
64
+ * Browser-compatible execution tracker
65
+ */
66
+ class BrowserExecutionTracker {
67
+ constructor(options = {}) {
68
+ var _a;
69
+ this._callStack = [];
70
+ this._executions = [];
71
+ this._currentExecution = null;
72
+ this._defaultThreshold = (_a = options.defaultThreshold) !== null && _a !== void 0 ? _a : 100; // ms
73
+ }
74
+ track(fn, options) {
75
+ var _a;
76
+ const fnName = (options === null || options === void 0 ? void 0 : options.label) || fn.name || '<anonymous>';
77
+ const threshold = (_a = options === null || options === void 0 ? void 0 : options.threshold) !== null && _a !== void 0 ? _a : this._defaultThreshold;
78
+ // Start timing
79
+ const startTime = performance.now();
80
+ // Add to call stack
81
+ this._callStack.push(fnName);
82
+ // Create execution record
83
+ const execution = {
84
+ name: fnName,
85
+ duration: 0,
86
+ isSlow: false,
87
+ level: this._callStack.length - 1,
88
+ startTime,
89
+ children: [],
90
+ };
91
+ // Set parent-child relationship
92
+ if (this._currentExecution) {
93
+ execution.parent = this._currentExecution;
94
+ this._currentExecution.children.push(execution);
95
+ }
96
+ else {
97
+ this._executions.push(execution);
98
+ }
99
+ // Save the previous current execution
100
+ const previousExecution = this._currentExecution;
101
+ // Set this as the current execution
102
+ this._currentExecution = execution;
103
+ try {
104
+ // Execute the function
105
+ return fn();
106
+ }
107
+ finally {
108
+ // End timing
109
+ const endTime = performance.now();
110
+ // Calculate duration
111
+ execution.duration = endTime - startTime;
112
+ // Check if it's a bottleneck
113
+ execution.isSlow = execution.duration > threshold;
114
+ // Restore the previous current execution
115
+ this._currentExecution = previousExecution;
116
+ // Remove from call stack
117
+ this._callStack.pop();
118
+ }
119
+ }
120
+ getCallStack() {
121
+ return [...this._callStack];
122
+ }
123
+ generateFlowChart() {
124
+ // Simplified flow chart for browser
125
+ let chart = 'Execution Flow:\n';
126
+ const flattenExecutions = (executions, level = 0) => {
127
+ executions.forEach(execution => {
128
+ const indent = ' '.repeat(level);
129
+ const duration = execution.duration.toFixed(2);
130
+ const slowMarker = execution.isSlow ? ' ⚠️ SLOW' : '';
131
+ chart += `${indent}${execution.name} (${duration}ms)${slowMarker}\n`;
132
+ if (execution.children && execution.children.length > 0) {
133
+ flattenExecutions(execution.children, level + 1);
134
+ }
135
+ });
136
+ };
137
+ flattenExecutions(this._executions);
138
+ return chart;
139
+ }
140
+ clear() {
141
+ this._executions = [];
142
+ this._currentExecution = null;
143
+ this._callStack = [];
144
+ }
145
+ }
146
+ /**
147
+ * Browser-compatible logger
148
+ */
149
+ class BrowserLogger {
150
+ constructor(config = {}) {
151
+ this._mode = 'dev';
152
+ this._indentLevel = 0;
153
+ this._mode = config.mode || 'dev';
154
+ this._executionTracker = new BrowserExecutionTracker({
155
+ defaultThreshold: config.performanceThreshold || 100,
156
+ });
157
+ this._performanceMonitor = new BrowserPerformanceMonitor({
158
+ defaultThreshold: config.performanceThreshold || 100,
159
+ });
160
+ }
161
+ info(message, ...args) {
162
+ this.log('info', message, args);
163
+ }
164
+ warn(message, ...args) {
165
+ this.log('warn', message, args);
166
+ }
167
+ error(message, ...args) {
168
+ this.log('error', message, args);
169
+ }
170
+ debug(message, ...args) {
171
+ if (this._mode === 'prod') {
172
+ return;
173
+ }
174
+ this.log('debug', message, args);
175
+ }
176
+ group(label) {
177
+ this.info(label);
178
+ this._indentLevel++;
179
+ if (typeof console.group === 'function') {
180
+ console.group(label);
181
+ }
182
+ }
183
+ groupEnd() {
184
+ if (this._indentLevel > 0) {
185
+ this._indentLevel--;
186
+ }
187
+ if (typeof console.groupEnd === 'function') {
188
+ console.groupEnd();
189
+ }
190
+ }
191
+ setMode(mode) {
192
+ this._mode = mode;
193
+ }
194
+ getMode() {
195
+ return this._mode;
196
+ }
197
+ track(fn, options) {
198
+ var _a;
199
+ const silent = (_a = options === null || options === void 0 ? void 0 : options.silent) !== null && _a !== void 0 ? _a : false;
200
+ // Track the function execution
201
+ const result = this._executionTracker.track(fn, options);
202
+ // Log the execution flow if not silent
203
+ if (!silent) {
204
+ const flowChart = this._executionTracker.generateFlowChart();
205
+ console.log(flowChart);
206
+ }
207
+ return result;
208
+ }
209
+ log(level, message, args) {
210
+ // Skip logs based on mode
211
+ if (this._mode === 'prod' && level !== 'error') {
212
+ return;
213
+ }
214
+ if (this._mode === 'staging' && (level === 'debug' || level === 'info')) {
215
+ return;
216
+ }
217
+ // Format the message
218
+ let formattedMessage;
219
+ if (typeof message === 'string') {
220
+ formattedMessage = message;
221
+ }
222
+ else {
223
+ try {
224
+ formattedMessage = JSON.stringify(message, null, 2);
225
+ }
226
+ catch (error) {
227
+ formattedMessage = String(message);
228
+ }
229
+ }
230
+ // Add indentation
231
+ const indent = ' '.repeat(this._indentLevel);
232
+ formattedMessage = `${indent}${formattedMessage}`;
233
+ // Log to console with appropriate method
234
+ switch (level) {
235
+ case 'info':
236
+ console.info(formattedMessage, ...args);
237
+ break;
238
+ case 'warn':
239
+ console.warn(formattedMessage, ...args);
240
+ break;
241
+ case 'error':
242
+ console.error(formattedMessage, ...args);
243
+ break;
244
+ case 'debug':
245
+ console.debug(formattedMessage, ...args);
246
+ break;
247
+ }
248
+ }
249
+ }
250
+ // Create a singleton instance of the browser logger
251
+ const browserLogger = new BrowserLogger();
252
+ // Export the singleton instance as the default export
253
+ export default browserLogger;
254
+ // Export a function to create a new logger instance
255
+ export function createBrowserLogger(config = {}) {
256
+ return new BrowserLogger(config);
257
+ }
258
+ // Export types and classes for advanced usage
259
+ export { BrowserLogger, BrowserExecutionTracker, BrowserPerformanceMonitor };
260
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,yBAAyB;IAI7B,YAAY,UAAyC,EAAE;;QAH/C,YAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;QAI/C,IAAI,CAAC,iBAAiB,GAAG,MAAA,OAAO,CAAC,gBAAgB,mCAAI,GAAG,CAAC,CAAC,KAAK;IACjE,CAAC;IAEM,UAAU,CAAC,KAAa;QAC7B,MAAM,EAAE,GAAG,GAAG,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,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AAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,MAAM;gBACT,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACzC,MAAM;YACR,KAAK,OAAO;gBACV,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,GAAG,IAAI,CAAC,CAAC;gBACzC,MAAM;QACV,CAAC;IACH,CAAC;CACF;AAED,oDAAoD;AACpD,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAE1C,sDAAsD;AACtD,eAAe,aAAa,CAAC;AAE7B,oDAAoD;AACpD,MAAM,UAAU,mBAAmB,CAAC,SAAiC,EAAE;IACrE,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,8CAA8C;AAC9C,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { ILoggerConfig, LogLevel, LogMode } from '../types';
2
+ /**
3
+ * Configuration manager for the logger
4
+ * Handles merging user config with defaults and provides utility methods
5
+ */
6
+ export declare class ConfigManager {
7
+ private _config;
8
+ /**
9
+ * Create a new ConfigManager instance
10
+ *
11
+ * @param userConfig - User-provided configuration options
12
+ */
13
+ constructor(userConfig?: Partial<ILoggerConfig>);
14
+ /**
15
+ * Get the current configuration
16
+ *
17
+ * @returns The current configuration
18
+ */
19
+ getConfig(): ILoggerConfig;
20
+ /**
21
+ * Update the configuration
22
+ *
23
+ * @param newConfig - New configuration options to merge
24
+ */
25
+ updateConfig(newConfig: Partial<ILoggerConfig>): void;
26
+ /**
27
+ * Get the current mode
28
+ *
29
+ * @returns The current mode
30
+ */
31
+ getMode(): LogMode;
32
+ /**
33
+ * Set the current mode
34
+ *
35
+ * @param mode - The mode to set
36
+ */
37
+ setMode(mode: LogMode): void;
38
+ /**
39
+ * Check if a log level should be displayed based on the current mode and level
40
+ *
41
+ * @param level - The log level to check
42
+ * @returns Whether the log level should be displayed
43
+ */
44
+ shouldLog(level: LogLevel): boolean;
45
+ /**
46
+ * Get the higher priority level between two log levels
47
+ *
48
+ * @param levelA - First log level
49
+ * @param levelB - Second log level
50
+ * @returns The higher priority level
51
+ */
52
+ private getHigherPriorityLevel;
53
+ /**
54
+ * Get the performance threshold
55
+ *
56
+ * @returns The performance threshold in milliseconds
57
+ */
58
+ getPerformanceThreshold(): number;
59
+ /**
60
+ * Get the indentation size
61
+ *
62
+ * @returns The number of spaces for each indentation level
63
+ */
64
+ getIndentSize(): number;
65
+ /**
66
+ * Check if colorization is enabled
67
+ *
68
+ * @returns Whether colorization is enabled
69
+ */
70
+ isColorEnabled(): boolean;
71
+ /**
72
+ * Check if timestamps are enabled
73
+ *
74
+ * @returns Whether timestamps are enabled
75
+ */
76
+ isTimestampEnabled(): boolean;
77
+ }