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!

✨ Key Featu…


This content originally appeared on DEV Community and was authored by Noureddine Belguinan

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

Or with Bun:

bun install pretty-js-log

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');

🔧 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!');

Logging Objects

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

logger('User data:', data);  // Objects are automatically formatted

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');

🤔 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!


This content originally appeared on DEV Community and was authored by Noureddine Belguinan


Print Share Comment Cite Upload Translate Updates
APA

Noureddine Belguinan | Sciencx (2024-11-06T18:48:29+00:00) Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨. Retrieved from https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/

MLA
" » Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨." Noureddine Belguinan | Sciencx - Wednesday November 6, 2024, https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/
HARVARD
Noureddine Belguinan | Sciencx Wednesday November 6, 2024 » Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨., viewed ,<https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/>
VANCOUVER
Noureddine Belguinan | Sciencx - » Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/
CHICAGO
" » Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨." Noureddine Belguinan | Sciencx - Accessed . https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/
IEEE
" » Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨." Noureddine Belguinan | Sciencx [Online]. Available: https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/. [Accessed: ]
rf:citation
» Introducing Pretty-js-log: Add Beautiful, Colorful Logging to Your Node.js Apps 🎨 | Noureddine Belguinan | Sciencx | https://www.scien.cx/2024/11/06/introducing-pretty-js-log-add-beautiful-colorful-logging-to-your-node-js-apps-%f0%9f%8e%a8/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.