DEV Community

Noureddine Belguinan
Noureddine Belguinan

Posted on

Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨

Ever wished your Node.js console logs were more visually appealing and easier to parse? Meet pretty-js-log, a lightweight logging package that brings color and structure to your console output while also supporting file logging!

Pretty JS Log Demo

✨ Key Features

  • 🎨 Colorful console output with different colors for different log levels
  • πŸ“ Built-in file logging support
  • ⚑ Works with both Node.js and Bun
  • πŸ•’ Timezone-aware timestamps
  • πŸ” Process ID tracking
  • 🎯 JSON/Array pretty formatting

πŸš€ Quick Start

Install with npm:

npm install pretty-js-log
Enter fullscreen mode Exit fullscreen mode

Or with Bun:

bun install pretty-js-log
Enter fullscreen mode Exit fullscreen mode

Basic usage:

const { logFactory } = require('pretty-js-log');

// Create a basic logger
const logger = logFactory({});

// Start logging!
logger('Hello World');
logger.info('This is an info message');
logger.warn('Warning! Something needs attention');
logger.error('Oops! Something went wrong');
logger.debug('Debug information');
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Advanced Usage

Save Logs to File

const logger = logFactory({
    path: './logs/app.log',  // Logs will be saved here
    id: process.pid          // Add process ID to logs
});

logger('This will be saved to the file too!');
Enter fullscreen mode Exit fullscreen mode

Logging Objects

const data = {
    user: 'john',
    age: 25
};

logger('User data:', data);  // Objects are automatically formatted
Enter fullscreen mode Exit fullscreen mode

Disable Console Output

If you want to write logs only to file without console output, use the toStdout option:

const logger = logFactory({
    path: './logs/app.log',
    toStdout: false    // Logs will only be written to the file only
});

logger('This will only appear in the log file');
logger.info('Silent logging to file');
Enter fullscreen mode Exit fullscreen mode

πŸ€” Why Another Logging Package?

  1. Simplicity: Just import and use - no complex configuration needed
  2. Lightweight: Minimal dependencies, perfect for small to medium projects
  3. Visual Appeal: Makes debugging more pleasant with color-coded log levels
  4. File Support: Built-in file logging without extra dependencies
  5. Modern: Works with both Node.js and Bun

πŸ”— Links

🀝 Contributing

This is an open-source project and we welcome contributions! Feel free to:

  • Open issues
  • Submit PRs
  • Suggest features
  • Help with documentation

πŸ“ˆ Future Plans

  • File size-based rotation
  • External logging API endpoints support

Give it a try and let me know what you think in the comments below!

Thanks!

Top comments (0)