Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rg-epic-logger

ronak-gondaliya385MIT1.3.1TypeScript support: included

The specification for a high-performance, flexible, and hybrid-capable Node.js logging system. It is designed to be zero-dependency by default, yet fully extendable via plugins and adaptable for browser or server environments.

logger, logging, nodejs, hybrid-logger, console, file-logger, json-logger, log-hooks, express-logger, remote-logging, crash-handler, plugin-system, debug, log-monitor, log-rotation, remote-logger

readme

🛠️ Custom Logger for Node.js

A lightweight, powerful, and flexible logging utility for Node.js applications. Simple to integrate and use without extra boilerplate code. Supports console and file logging with daily rotation, user-configurable 12 or 24-hour timestamp format, formatted timestamps, log levels, automatic log cleanup, an Express request/response watchman, and more.


✨ Features That Developers Love

  • Lightweight and Simple: Easy to configure and use with sensible defaults.
  • Console Logging with colorful prefixes
  • 🗂️ File Logging with daily rotation and size-based backups
  • 🧠 Supports 8 log levels:
    • DEBUG, INFO, SUCCESS, WARN, ERROR, FATAL, HTTP, and CUSTOM
  • ⏱️ Configurable Time Format: Choose between 12-hour or 24-hour timestamp display.
  • 🧾 Format Options: plain or json
  • 🧭 Timezone-aware timestamps (IST, UTC, etc.)
  • 📦 Auto-creates /logs directory for you
  • ♻️ Auto-delete old log files based on backups count
  • 🎨 Color-coded outputs (like cyan for debug, red for error)
  • 🕵️ Express Watchman: Automatically log incoming requests and outgoing responses for Express apps (console & file).
  • 🧩 Pluggable architecture (remote logging coming soon!)

📦 Installation

npm install rg-epic-logger

🚀 Getting Started

💻 Console Logger Example

const Logger = require('rg-epic-logger').default;

const logger = new Logger({
    level: 'DEBUG',
    format: 'plain',
    console: true,
    consolePrefix: 'App',
    timezone: 'IST'
});

logger.debug('Debugging started...');
logger.success('Operation completed successfully!');
logger.warn('Something might be wrong...');
logger.error('An error occurred!');
logger.info('This is some information.');

🕵️ Express Watchman Example (Easy Setup!)

Automatically log incoming requests and outgoing responses for your Express server with minimal setup. Initialize the logger, ensuring watch: true (which is the default). The logger will then automatically monitor Express activity for you.

const Logger = require('rg-epic-logger').default;
const express = require('express'); // Make sure Express is required somewhere in your project

const app = express();
const port = 3000;

// Initialize Logger with Watchman enabled
// Setting watch: true automatically activates request/response logging
// for Express applications running in this process.
const logger = new Logger({
    level: 'DEBUG',
    format: 'plain',
    watch: true,           // <<< Setting this to true enables AND activates the watchman
    watchPrefix: 'Watch',  // <<< Customize the prefix for watched logs
    timezone: 'IST'
});

// --- NO explicit middleware setup needed! ---
// If 'watch: true', the logger monitors Express automatically.

// Example route
app.get('/', (req, res) => {
    // Regular logs still work using 'consolePrefix' (default 'Application')
    // logger.info('Handling GET / request');
    res.send('Hello World!');
    // Request ('/') and Response ('Hello World!') details will be automatically
    // logged by the watchman using the 'Watch' prefix.
});

app.listen(port, () => {
    logger.success(`Server listening on port ${port}`); // Regular log
});

🗂️ File Logger with Daily Rotation and Auto-Backup

const Logger = require('rg-epic-logger').default;

const logger = new Logger({
    level: 'INFO',
    format: 'plain',
    fileRotate: true,
    fileFormat: 'DD-MM-YYYY',
    fileBackups: 2,  // keep only last 2 days log files
    fileSize: 10,   // max file size in MB before rotating
    timezone: 'IST',
    use24Hour: true // Explicitly set for clarity (default is true)
});

logger.info('Logging to file with daily rotation.');

📁 Logs are stored in /logs and named like:

logs/
├── Application/              # Regular logs (from logger.info, etc.)
│   ├── 15-04-2025.log
│   └── 14-04-2025.log        # Example previous day's log
└── Global/                   # Watched request/response logs
    ├── 15-04-2025.log
    └── 14-04-2025.log        # Example previous day's log

After reaching the fileBackups limit (e.g. 2), older logs will be automatically deleted.


🔥 Full List of Log Levels

Level Description Color
DEBUG Detailed debug info Cyan
INFO General application info Blue
SUCCESS Operation completed correctly Green
WARN Something needs attention Yellow
ERROR Something went wrong Red
FATAL Critical issue, app may crash Magenta
HTTP Web traffic or request info White
CUSTOM For custom use cases Bright Gray

⚙️ Configuration Options

Option Description Default
level Minimum log level to record INFO
format Output format (plain or json) plain
console Enable console logging true
consolePrefix Console log prefix Application
watch Enable Express request/response watchman middleware true
watchPrefix Prefix for watched logs (console & file) Global
fileRotate Enable file rotation true
fileFormat File name date format (DD-MM-YYYY or DD-MM-YYYY/HH) DD-MM-YYYY
fileBackups Number of rotated files to keep 7
fileSize Max file size in MB before rotation 10
timezone Timezone for timestamps IST

📅 File Format & Cleanup Behavior

🗂 fileFormat Options

Format Description Example File Structure
DD-MM-YYYY Daily log rotation /logs/11-04-2025.log
DD-MM-YYYY/HH Hourly rotation in folders /logs/11-04-2025/13.log

This allows you to organize logs by day or by hour, especially useful for high-frequency logging systems.

💾 fileSize

  • Controls maximum file size (in MB) before rotation.
  • Example: fileSize: 10 will rotate when the log file exceeds 10 MB.
  • Once a log file hits the size limit, it's archived, and a new one is created automatically.

Older logs are cleaned up based on the fileBackups limit.


📁 Log File Structure with Watchman Enabled

When both fileRotate: true and watch: true are enabled, logs are automatically separated into directories based on their prefixes:

- **Regular Logs**: Use the consolePrefix (Default: Application)
- **Watched Logs**: Use the watchPrefix (Default: Global)

Example structure with fileFormat: 'DD-MM-YYYY' (Assuming today is April 15, 2025):

logs/
├── Application/         # Regular logs via logger.info(), .debug(), etc.
│   ├── 15-04-2025.log   # Current log file
│   └── 14-04-2025.log   # Previous day's log (kept based on fileBackups)
└── Global/              # Watched request/response logs via logger.watchman()
    ├── 15-04-2025.log   # Current log file
    └── 14-04-2025.log   # Previous day's log (kept based on fileBackups)
  • Example structure with fileFormat: 'DD-MM-YYYY/HH' (Assuming current time is 14:xx on April 15, 2025):
logs/
├── Application/
│   └── 15-04-2025/
│       ├── 14.log       # Current hour's log file
│       └── 13.log       # Previous hour's log (kept based on fileBackups)
└── Global/
    └── 15-04-2025/
        ├── 14.log       # Current hour's log file
        └── 13.log       # Previous hour's log (kept based on fileBackups)

Important:

  1. The /logs directory and prefix subdirectories (Application, Global) are created automatically if they don't exist.
  2. Cleanup: The fileBackups limit applies independently to each log prefix directory. With fileBackups: 2, the logger will keep the latest 2 log files/folders for Application and the latest 2 for Global. Older ones for each prefix are deleted.

⚡ Tip: Benchmark Your Logs

for (let i = 0; i < 10000; i++) {
    logger.info(`Log entry #${i}`);
}

Great for performance/load testing!


🚧 Coming Soon

I'm actively working on adding more powerful features to make this logger even more epic:

  • ☁️ Remote Logging Support (Log to a remote server or cloud storage)
  • 📊 Web Dashboard (View, search, and filter logs in real-time)
  • 📬 Email & Slack Alerts for ERROR or FATAL logs
  • 🧪 Unit Tests for rock-solid reliability
  • 🔐 Encrypted Log Files for sensitive environments
  • Async Logging Queue to avoid I/O blocking
  • 🧰 CLI Tool to tail and search logs from the terminal

Have a feature in mind?
📩 Please email at gondaliya.ronak100@gmail.com


🧑‍💻 Author

Made with ❤️ by [Ronak Gondaliya]
📨 Contact