npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@imcooder/node-logger

v2.1.0

Published

A lightweight, high-performance Node.js logging library with auto cleanup

Readme

node-logger

A lightweight, high-performance Node.js logging library designed to be more efficient than log4js.

NPM version npm download David deps

Features

  • High Performance: Optimized for better performance than log4js
  • Lightweight: Minimal dependencies and overhead
  • Auto Rotation: Hourly log file rotation (format: filename.YYYYMMDDHH)
  • Multi-level Logging: DEBUG, TRACE, INFO, WARN, ERROR levels
  • Dual Output: Independent console and file logging
  • Request Tracing: Built-in request lifecycle logging with unique IDs
  • Auto Cleanup: Automatic old log file cleanup with configurable TTL
  • Console Replacement: Optional interception of standard console calls
  • Async Operations: Non-blocking file operations for better performance

Changelog

See CHANGELOG.md for detailed version history.

Installation

npm install @imcooder/node-logger --save

Configuration

Configuration Options

let config = {
    main: { // Logger name, used in log format and supports multiple file outputs
        'log_file': path.join(logDir, './node.log'), // Log file path, no file output if not configured
        "time_format": "%F %T.%L", // Time format in log lines
        "auto_rotate": true, // Auto-rotate log files, format: filename.YYYYMMDDHH
        "level": "INFO", // Minimum log level to output
        "console": true, // Whether to output to console simultaneously
        "ttl_hour": 72, // NEW: Log file TTL in hours, auto-cleanup old files (optional)
        "max_buffer_size": 1000, // Buffer size when stream is draining (default: 1000)
        "high_water_mark": 1048576 // Stream high water mark in bytes (default: 1MB)
    },
    trace: { // Secondary logger for trace/debug information
        'log_file': path.join(logDir, './trace.log'),
        "time_format": "%F %T.%L",
        "auto_rotate": true,
        "level": "DEBUG",
        "console": false, // Trace logs only to file, not console
        "ttl_hour": 24 // Keep trace logs for 1 day only
    },
    "replaceConsole": true // System console logs follow this format but don't write to file
};

Time Format Reference: https://github.com/samsonjs/strftime

Configuration Parameters

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | log_file | string | - | Path to log file. If not set, no file output | | time_format | string | %F %T.%L | Time format in log lines | | auto_rotate | boolean | true | Enable hourly log file rotation | | level | string | DEBUG | Minimum log level (DEBUG/TRACE/INFO/WARN/ERROR) | | console | boolean | false | Output to console simultaneously | | ttl_hour | number | 72 | NEW: Auto-cleanup files older than N hours (0 = disabled) | | max_buffer_size | number | 1000 | Buffer size when stream is draining | | high_water_mark | number | 1048576 | Stream high water mark in bytes (1MB) | | replaceConsole | boolean | false | Global: Replace system console with formatted output |

Log Levels

Log levels in ascending order: DEBUGTRACEINFOWARNERROR

🆕 Auto Cleanup Feature

The ttl_hour configuration enables automatic cleanup of old rotated log files:

How It Works

  • Purpose: Prevents disk space issues from accumulating log files
  • Mechanism: Automatically deletes log files older than specified hours based on file modification time
  • Schedule: First cleanup 1 minute after startup, then every 30 minutes
  • Requirements: Must be used with auto_rotate: true
  • File Pattern: Only processes files matching filename.YYYYMMDDHH format
  • Async Operations: Uses non-blocking file operations for better performance

Configuration Examples

// Different TTL for different loggers
{
    main: {
        'log_file': './logs/app.log',
        'auto_rotate': true,
        'ttl_hour': 168  // Keep main logs for 1 week (7 × 24 hours)
    },
    error: {
        'log_file': './logs/error.log',
        'auto_rotate': true,
        'ttl_hour': 720  // Keep error logs for 1 month (30 × 24 hours)
    },
    debug: {
        'log_file': './logs/debug.log',
        'auto_rotate': true,
        'ttl_hour': 24   // Keep debug logs for 1 day only
    }
}

Cleanup Behavior

  • Default: ttl_hour: 72 → Delete files older than 72 hours (3 days)
  • ttl_hour: 0Disable cleanup (no automatic cleanup)
  • ttl_hour: 24 → Delete files older than 24 hours
  • Files not matching rotation pattern are ignored (safe)
  • Service starts automatically when nodeLogger.configure() is called
  • Service stops automatically when nodeLogger.shutdown() is called

Usage

Basic Setup

const nodeLogger = require('@imcooder/node-logger');
const path = require('path');

const logDir = path.join(__dirname, '../log');

const config = {
    main: {
        'log_file': path.join(logDir, './node.log'),
        "time_format": "%F %T.%L",
        "auto_rotate": true,
        "level": "INFO",
        "console": true,
        "ttl_hour": 72  // Keep logs for 3 days
    },
    trace: {
        "time_format": "%F %T.%L",
        'log_file': path.join(logDir, './trace.log'),
        "auto_rotate": true,
        "level": "DEBUG",
        "console": false,
        "ttl_hour": 24  // Keep trace logs for 1 day
    },
    "replaceConsole": true
};

nodeLogger.configure(config);

Standard Logging

Direct logging output for each call:

const logger = nodeLogger.getLogger('main');

logger.debug('debug message');
logger.trace('trace message');
logger.info('info message');
logger.notice('notice message');
logger.log('log message');
logger.warn('warning message');
logger.error('error message');
logger.fatal('fatal error');

// Formatted logging with placeholders
logger.info('User %s performed action: %s', userId, actionName);
logger.debug('Request data: %j', requestData);

Request Tracing

Collect multiple log entries and output once - ideal for request/response logging:

// Create tracer with logger name and unique request ID
const tracer = nodeLogger.create('main', 'req_12345');

tracer.debug('Processing request');
tracer.gather('request', { url: '/api/users', method: 'GET' });
tracer.gather('response', { status: 200, duration: '45ms' });

// Output all collected data at INFO level
tracer.dumps();

// Direct logging (outputs immediately, no collection)
tracer.debug('Additional debug info');
tracer.error('Request failed');

Manual Cleanup

For testing or manual cleanup operations:

// Manually trigger cleanup once
await nodeLogger.cleanupNow();

// Graceful shutdown (stops cleanup service)
await nodeLogger.shutdown();