1.0.2 • Published 8 months ago

console-enhance v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

console-enhance

šŸš€ A powerful console logging enhancement library for Node.js applications that adds colors, timestamps, and advanced debugging features.

šŸ“‹ 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

šŸš€ Installation

npm install console-enhance
# or
yarn add console-enhance
# or
pnpm add console-enhance

šŸŽÆ Quick Start

import { log } from "console-enhance";

// Basic logging
log("Hello, World!");
// Output: [2024-03-21 10:30:45] Hello, World!

ā±ļø Performance Timing

// Measure operation duration
log.time("database-query");
await fetchDataFromDB();
log.timeEnd("database-query");
// Output: [10:30:45] database-query: 123ms

šŸ’¾ Memory Monitoring

// Track memory usage
log.memory();
//Output: Memory impact: 0MB

šŸ” Debug with Stack Traces

// 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)

āš™ļø Configuration

log.configure({
  showTimestamp: true,
  dateFormat: "YYYY-MM-DD HH:mm:ss",
  colors: true,
  logLevel: "info",
  prefix: "MyApp",
  outputFile: "app.log", // Optional file logging
});

šŸ“– API Reference

Log Levels

MethodDescriptionUse Case
log(message)Standard loggingGeneral purpose logging

Utility Methods

MethodDescription
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

Configuration Options

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
}

šŸ¤ Contributing

Contributions are welcome! Please read our contributing guidelines for details.

šŸ“„ License

MIT

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago