jt-debugger
v1.0.0
Published
A features rich JavaScript & TypeScript debugger
Maintainers
Readme
JT-Debugger
A feature-rich JavaScript & TypeScript debugger with advanced logging, profiling, and memory tracking capabilities.
made with love 💖 by @Gurveer
Features
- 🎯 Multiple Log Levels (DEBUG, INFO, WARN, ERROR, SUCCESS)
- 📝 File-based Logging with Rotation
- 🔍 Function Performance Tracking
- 📊 Memory Usage Monitoring
- ⏱️ Execution Time Profiling
- 🎨 Customizable Log Formatting
- 🔎 Log Filtering
- 🌐 Remote Logging Support
- ⚡ Asynchronous Function Support
Installation
npm install jt-debuggerBasic Usage
import Debugger from 'jt-debugger';
// Initialize with default options
const debug = new Debugger();
// Basic logging
debug.info('Application started');
debug.debug('Debug message');
debug.warn('Warning message');
debug.error('Error occurred');
debug.success('Operation successful');Advanced Configuration
const debug = new Debugger({
enable: true, // Enable/disable logging
logToFile: true, // Save logs to file
logFilePath: 'debug.log', // Log file path
logLevel: 'DEBUG', // Minimum log level
maxLogSize: 5 * 1024 * 1024,// Max log file size (5MB)
maxLogFiles: 5, // Number of log files to keep
colors: { // Custom colors for log levels
DEBUG: 'blue',
INFO: 'cyan',
WARN: 'yellow',
ERROR: 'red',
SUCCESS: 'green'
},
timeFormat: 'ISO', // 'ISO' or 'locale'
filterPattern: '^Test' // RegExp pattern for filtering logs
});Function Performance Tracking
// Track function execution time and parameters
const myFunction = debug.trackFunction(async (param1, param2) => {
// Your function logic here
return result;
}, 'myCustomFunctionName');
// The tracked function will log:
// - Function call with parameters
// - Execution time
// - Return value or errorMemory Usage Monitoring
// Get memory snapshots
const memorySnapshots = debug.getMemoryUsage();
// Clear memory usage history
debug.clearMemoryUsage();Dynamic Log Level and Filtering
// Change log level at runtime
debug.setLogLevel('INFO');
// Set or update filter pattern
debug.setFilterPattern('^API');
// Remove filter
debug.setFilterPattern(null);API Reference
Constructor Options
| Option | Type | Default | Description | | ------------- | -------------- | ----------- | ---------------------------- | | enable | boolean | true | Enable/disable logging | | logToFile | boolean | false | Save logs to file | | logFilePath | string | 'debug.log' | Log file path | | logLevel | string | 'DEBUG' | Minimum log level | | maxLogSize | number | 5MB | Max log file size | | maxLogFiles | number | 5 | Number of log files to keep | | colors | object | {...} | Custom colors for log levels | | timeFormat | string | 'ISO' | Timestamp format | | filterPattern | string|RegExp | null | Log filter pattern |
Methods
debug(message, ...args): Log debug messageinfo(message, ...args): Log info messagewarn(message, ...args): Log warning messageerror(message, ...args): Log error messagesuccess(message, ...args): Log success messagetrackFunction(fn, fnName?): Track function performancegetMemoryUsage(): Get memory usage snapshotsclearMemoryUsage(): Clear memory usage historysetLogLevel(level): Change log levelsetFilterPattern(pattern): Set log filter pattern
TypeScript Support
The package includes TypeScript definitions and supports type checking out of the box.
import Debugger from 'jt-debugger';
interface Config {
name: string;
value: number;
}
const debug = new Debugger();
debug.info('Config:', { name: 'test', value: 42 } as Config);License
MIT
