@windowsworldcartoon/debugkit
v1.1.0
Published
A Debugging tool for develepers
Downloads
8
Maintainers
Readme
DebugKit v1.1.0
A comprehensive debugging and logging toolkit for Node.js
Overview
DebugKit is a lightweight yet powerful debugging library for Node.js that provides a simple and intuitive way to log, inspect, and debug your code. Features timestamps, stack traces, performance monitoring, and more.
Features
- Enhanced Logging: Log messages with optional timestamps and multiple log levels (log, warn, error, info, debug)
- Object Inspection: Inspect variables and objects with formatted JSON output and optional labels
- Error Handling: Log errors with optional stack traces for better debugging
- Performance Monitoring: Built-in timers, counters, and performance metrics
- Console Utilities: Table formatting, stack traces, grouped output, assertions, and more
- Timestamp Support: Add ISO timestamps to any log message
- Batch Logging: Log multiple messages at once with
logMultiple()
Installation
To install DebugKit, run the following command:
npm install @windowsworldcartoon/debugkitUsage
Basic Logging
const debug = require('@windowsworldcartoon/debugkit');
// Simple logging
debug.log('This is a log message');
debug.warn('This is a warning');
debug.info('This is info');
debug.error('This is an error');
debug.debug('This is a debug message');
// With timestamps
debug.log('Message with timestamp', true);
debug.warn('Warning with timestamp', true);Object Inspection
// Inspect objects with formatted JSON
debug.inspect({ a: 1, b: 2 });
// With a label
debug.inspect({ name: 'John', age: 30 }, 'User Object');Error Handling
// Log error with stack trace
try {
throw new Error('Something went wrong');
} catch (err) {
debug.error(err.message, true); // true = include stack trace
}Performance Monitoring
// Time execution
debug.time('myTimer');
// ... some code ...
debug.timeEnd('myTimer');
// Count occurrences
debug.count('loop-iteration');
debug.count('loop-iteration');
debug.count('loop-iteration'); // Outputs: loop-iteration: 3Console Utilities
// Display data in table format
debug.table([
{ name: 'John', age: 30 },
{ name: 'Jane', age: 25 }
]);
// Grouped output
debug.group('My Group');
debug.log('Item 1');
debug.log('Item 2');
debug.groupEnd();
// Stack trace
debug.trace('Custom trace label');
// Assertion
debug.assert(value === expected, 'Values do not match');
// Clear console
debug.clear();
// Log multiple messages
debug.logMultiple(['Message 1', 'Message 2', 'Message 3']);API Reference
Core Methods
| Method | Parameters | Description |
|--------|-----------|-------------|
| log(message, includeTimestamp) | message: any, includeTimestamp: boolean | Log a message with optional timestamp |
| error(message, includeStack) | message: string/Error, includeStack: boolean | Log an error with optional stack trace |
| warn(message, includeTimestamp) | message: any, includeTimestamp: boolean | Log a warning message |
| info(message, includeTimestamp) | message: any, includeTimestamp: boolean | Log an info message |
| debug(message, includeTimestamp) | message: any, includeTimestamp: boolean | Log a debug message |
Utility Methods
| Method | Parameters | Description |
|--------|-----------|-------------|
| inspect(object, label) | object: any, label: string | Inspect and log object as formatted JSON |
| table(data) | data: Array/Object | Display data in table format |
| trace(label) | label: string | Log a stack trace |
| assert(condition, message) | condition: boolean, message: string | Assert a condition |
| group(label) | label: string | Start a console group |
| groupEnd() | none | End a console group |
| time(label) | label: string | Start a timer |
| timeEnd(label) | label: string | End a timer and log elapsed time |
| count(label) | label: string | Count occurrences |
| clear() | none | Clear console output |
| logMultiple(messages) | messages: Array | Log multiple messages at once |
Changelog
v1.1.0
- Enhanced existing logging methods with timestamp support
- Added error logging with optional stack traces
- New utility methods:
table(),trace(),assert(),group(),groupEnd(),time(),timeEnd(),count(),clear(),logMultiple() - Improved
inspect()method with optional labels - Added comprehensive JSDoc documentation
- Changed variable declaration from
vartoconst
v1.0.4
- Initial release with basic logging functionality
License
This project is licensed under the MIT License.
MIT License Details
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright
Copyright © 2025 windowsworldcartoon. All rights reserved.
For the full license text, see the LICENSE file in the repository.
