DEV Community

Noureddine Belguinan
Noureddine Belguinan

Posted on

4

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!

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more