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

logsave-hub

v2.0.0

Published

Ethical dual-mode Automatic log rotation and persistent logging for Node.js (ESM + CJS)

Readme

npm version npm downloads license

logsave-hub 🚀

logsave-hub is an ethical, easy-to-use logging utility for Node.js that supports both automatic console logging and explicit log APIs, with full ESM + CommonJS compatibility.

It is designed to be:

  • ✅ Beginner-friendly
  • ✅ Explicit & ethical (no hidden side effects)
  • ✅ Works in both ESM and CJS
  • ✅ Production-ready
  • ✅ Built with TypeScript

✨ Features

  • 📁 Automatically creates a log directory
  • 🕒 Timestamped daily log files
  • 🖥 Optional console.log / warn / error override
  • ✍️ Explicit logging API (log.save, log.warn, log.error)
  • 🔄 Works in ESM and CommonJS
  • 🔒 No cloud upload, no data sharing — local only
  • 🗑 Automatic log retention & cleanup (optional, default: 30 days)
  • 📊 Built-in live web dashboard for real-time log viewing
  • 🔌 Easy integration with Express + Socket.IO via dashboardRouter and attachDashboard

📦 Installation

Install using npm:

npm install logsave-hub

You'll also need express and socket.io if you want to use the live dashboard:

npm install express socket.io

🚀 Basic Usage

logsave-hub exposes two modes:

  1. Console override mode (automatic)
  2. Explicit logging mode (log.save())

You must explicitly initialize logging using enableLogging().


1️⃣ Console Override Mode (Automatic Logging)

In this mode, all console.log, console.warn, and console.error are automatically written to log files.

▶️ ESM Example

import enableLogging from "logsave-hub";

enableLogging({
  override: true,
  outDir: "./logs"
});

console.log("Server started");
console.warn("Low memory");
console.error("Something went wrong");

▶️ CommonJS Example

const enableLogging = require("logsave-hub");

enableLogging({
  override: true,
  outDir: "./logs"
});

console.log("Server started");
console.warn("Low memory");
console.error("Something went wrong");

2️⃣ Explicit Logging Mode (log.save())

In this mode, the console is not overridden. You explicitly control what gets logged.

▶️ ESM Example

import enableLogging, { log } from "logsave-hub";

enableLogging({
  override: false,
  outDir: "./logs"
});

log.save("Application started");
log.warn("Cache is almost full");
log.error("Database connection failed");

▶️ CommonJS Example

const enableLogging = require("logsave-hub");
const { log } = require("logsave-hub");

enableLogging({
  override: false,
  outDir: "./logs"
});

log.save("Application started");
log.warn("Cache is almost full");
log.error("Database connection failed");

🗂 Log Output

Logs are written to the specified directory (default: ./logs):

logs/
└─ app-2025-12-19.log

Example log content:

2025-12-19 17:16:21 [INFO] Server started
2025-12-19 17:16:31 [WARN] Cache is almost full
2025-12-19 17:16:41 [ERROR] Database connection failed

🗑 Log Retention

logsave-hub can automatically clean up old log files so your logs directory doesn't grow indefinitely.

  • Retention period: 30 days by default when enabled
  • Runs once on startup, then on a recurring schedule
  • Fails silently — retention cleanup will never crash your app
  • Disable it by setting retention: false

📊 Live Web Dashboard

logsave-hub ships with a built-in real-time dashboard for viewing your logs in the browser — just mount the router and attach it to a Socket.IO server.

Features:

  • 🔴 Live streaming of new log entries via WebSockets
  • 📁 Browse and view historical daily log files
  • 🔍 Search and filter logs by level (Info / Warn / Error)
  • 📈 Live session stats (total / info / warn / error counts)
  • 📱 Responsive layout for desktop and mobile

▶️ ESM Example

import express from "express";
import { Server } from "socket.io";
import http from "http";
import enableLogging, { attachDashboard, dashboardRouter } from "logsave-hub";

const app = express();
const server = http.createServer(app);
const io = new Server(server);

attachDashboard(io);
app.use("/logsave-hub", dashboardRouter);

enableLogging({
  override: true,
  outDir: "./logs",
  retention: false
});

server.listen(3000, () => {
  console.log("Listening on port 3000");
});

console.log("Server started");
console.warn("Server started");
console.error("Server started");

▶️ CommonJS Example

const enableLogging = require("logsave-hub").default;
const { log, dashboardRouter, attachDashboard } = require("logsave-hub");
const express = require("express");
const { Server } = require("socket.io");
const http = require("http");

const app = express();
const server = http.createServer(app);
const io = new Server(server);

attachDashboard(io);
app.use("/logsave-hub", dashboardRouter);

enableLogging({
  override: true,
  outDir: "./logs",
  retention: true,
});

console.log("Server started");
console.warn("Server started");
console.error("Server started");

server.listen(3000);

setInterval(() => {
  log.save("Ping at", new Date().toISOString());
  log.warn("Ping at", new Date().toISOString());
  log.error("Ping at", new Date().toISOString());
}, 10000);

Once running, open http://localhost:3000/logsave-hub (or whichever path you mounted the router on) to view the live dashboard.


⚙️ Configuration Options

enableLogging({
  override?: boolean;   // default: true
  outDir?: string;      // default: "./logs"
  retention?: boolean;  // default: true
});

| Option | Description | |-------------|------------| | override | Whether to override console.log | | outDir | Directory where logs are stored | | retention | Whether to automatically purge old log files |


❗ Important Notes

  • enableLogging() must be called before using log.save()
  • Calling enableLogging() multiple times is safe
  • Logs are stored locally only
  • No network, no cloud, no tracking

🧠 Why logsave-hub?

Many loggers either:

  • Are too complex ❌
  • Don't support both ESM & CJS ❌

logsave-hub is designed to be:

  • Explicit
  • Predictable
  • Easy to integrate
  • Safe for beginners and professionals

🧪 Supported Environments

  • Node.js 20+
  • Node.js 22+
  • Node.js 24+

📜 License

MIT © Koda Adam


❤️ Contributing

Pull requests and suggestions are welcome. This package is built for the community.