🚀 A powerful console logging enhancement library for Node.js applications that adds colors, timestamps, and advanced debugging features.
- 🎨 Rich colored output for better visibility
- ⏰ Customizable timestamp formats
- 📊 Real-time memory usage monitoring
- ⏱️ High-precision performance timing
- 🔍 Detailed stack trace support
- ⚙️ Flexible configuration options
- 🌈 Multiple log levels with visual distinction
- 🔄 Async operation support
npm install console-enhance
# or
yarn add console-enhance
# or
pnpm add console-enhance
import { log } from "console-enhance";
// Basic logging
log("Hello, World!");
// Output: [2024-03-21 10:30:45] Hello, World!
// Measure operation duration
log.time("database-query");
await fetchDataFromDB();
log.timeEnd("database-query");
// Output: [10:30:45] database-query: 123ms
// Track memory usage
log.memory();
//Output: Memory impact: 0MB
// Get detailed error information
log.trace("Authentication failed");
// Output: [10:30:45] Authentication failed
// at AuthService.validate (/src/auth.ts:45:5)
// at Router.authenticate (/src/routes.ts:12:3)
log.configure({
showTimestamp: true,
dateFormat: "YYYY-MM-DD HH:mm:ss",
colors: true,
logLevel: "info",
prefix: "MyApp",
outputFile: "app.log", // Optional file logging
});
Method | Description | Use Case |
---|---|---|
log(message) |
Standard logging | General purpose logging |
Method | Description |
---|---|
log.time(label) |
Start a performance timer |
log.timeEnd(label) |
End timer and show duration |
log.memory() |
Show memory statistics |
log.trace(message) |
Log with stack trace |
log.clear() |
Clear console output |
interface LogOptions {
showTimestamp?: boolean; // Show/hide timestamps
dateFormat?: string; // Moment.js format string
colors?: boolean; // Enable/disable colors
logLevel?: "debug" | "info" | "warn" | "error"; // Minimum log level
prefix?: string; // Add prefix to all logs
outputFile?: string; // File to write logs to
maxFileSize?: number; // Max log file size in MB
compress?: boolean; // Compress old log files
}
Contributions are welcome! Please read our contributing guidelines for details.
MIT