consoleBetter is a TypeScript library that enhances the JavaScript console with additional logging capabilities, allowing for improved debugging and performance tracking. It provides a simple interface for logging messages with different levels, toggling debug mode, and measuring performance for specific functions.
- Logging with Levels: Log messages with different severity levels: DEBUG, INFO, WARN, ERROR, and FUNKY.
- Debug Toggle: Enable or disable debug logging dynamically.
- Performance Tracking: Measure and log the execution time of functions to identify performance bottlenecks.
To install consoleBetter, you can use:
NPM
npx jsr add @razmans/console-betterDeno
deno add jsr:@razmans/console-betterYarn
yarn dlx jsr add @razmans/console-betterPnpm
pnpm dlx jsr add @razmans/console-betterBun
bunx jsr add @razmans/console-betterFirst, import the consoleBetter library in your TypeScript file:
import { LogLevel, Log } from "@razmans/console-better";You can log messages using different log levels:
Log('This is a debug message.', LogLevel.DEBUG);
Log('This is an informational message.', LogLevel.INFO);
Log('This is a warning message.', LogLevel.WARN);
Log('This is an error message.', LogLevel.ERROR);
Log('This is a funky message!', LogLevel.FUNKY);
Log('This is a high priority message!', LogLevel.HIGH);
Log('This is a medium priority message!', LogLevel.MEDIUM);
Log('This is a low priority message!', LogLevel.LOW);
Log('This is a Pikachu message!',LogLevel.PIKACHU);You can track the performance of any function by wrapping it in trackPerformance:
TrackPerformance(() => {
// Your code here
});
//You can also set iterations
TrackPerformance(() => {
// Code to set 552 iterations
}, 552);
//You can also set iterations + threshold
TrackPerformance(() => {
// Code to set 1000 iterations with a threshold of 7 ms
}, 1000, 7);Here's a complete example demonstrating the usage of consoleBetter:
import { LogLevel,Log } from "@razmans/console-better";
// Log messages
Log('This is a debug message.', LogLevel.DEBUG);
Log('This is an informational message.', LogLevel.INFO);
// Track performance
TrackPerformance(() => {
let sum = 0;
for (let i = 0; i < 1e6; i++) {
sum += i;
}
log.better(`Sum is: ${sum}`, LogLevel.INFO);
});
// Track performance, run it 11 times
TrackPerformance(() => {
let sum = 0;
for (let i = 0; i < 1e6; i++) {
sum += i;
}
log.better(`Sum is: ${sum}`, LogLevel.INFO);
},11);
// Track performance, run it 33 times with a threshold of 12ms
TrackPerformance(() => {
let sum = 0;
for (let i = 0; i < 1e6; i++) {
sum += i;
}
log.better(`Sum is: ${sum}`, LogLevel.INFO);
},33, 12);This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
Special thanks to the community for their support and feedback.