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

log-vani

v1.0.6

Published

A customizable and file-based logger with rate limiting and log rotation.

Readme

Log-Vani

A robust and customizable logging library for Node.js applications. log-vani supports multiple log levels, customizable formats, color-coded output, JSON logging, and integration with custom log transports, making it suitable for both development and production environments.

Installation

Install log-vani using npm:

npm install log-vani

Usage

Basic Usage

const Logger = require("log-vani");

// Create a new Logger instance
const logger = new Logger({
  logFile: "path/to/your/logfile.log", // Path to the log file
});

// Log messages with different levels
logger.info("This is an info message");
logger.warn("This is a warning message");
logger.error("This is an error message");
logger.debug("This is a debug message");

Log Levels

  • info: Informational messages
  • warn: Warning messages
  • error: Error messages
  • debug: Debugging messages

Custom Log Formats

You can customize the log format using the format option. The default format is:

[{level}] {message} at {timestamp}

You can replace this format with your custom string containing placeholders:

  • {level}: The log level (e.g., INFO, WARN, ERROR, DEBUG).
  • {message}: The log message.
  • {timestamp}: The current timestamp.

Example of Custom Format

const logger = new Logger({
  logFile: "path/to/your/logfile.log",
  format: "{level} - {message} at {timestamp} from {hostname}",
});

Color-Coded Logs

Each log level is color-coded for better readability in the terminal. The default colors are:

  • info: Green
  • warn: Yellow with Magenta background
  • error: Red with White background
  • debug: Cyan

You can customize the colors in the terminal output.

Custom Transport

You can send logs to external services (e.g., a logging server) using the customTransport option. The transport must implement a send method.

Example

const logger = new Logger({
  logFile: "path/to/your/logfile.log",
  customTransport: {
    send: function (log) {
      console.log("Sending log to external service:", log);
    },
  },
});

logger.info("This log will be sent to an external service");

JSON Logging

If you prefer logging in JSON format, you can use the logAsJson method. This is especially useful for log aggregation systems.

logger.logAsJson("info", "This is a JSON log entry");

Clearing Logs

Clear the log file using the clearLogs method. This is useful when you need to reset logs between runs.

logger.clearLogs();

Rate Limiting

Control the rate at which logs are written using the rateLimit option. This prevents spamming logs in high-frequency scenarios.

const logger = new Logger({
  rateLimit: 2000, // Minimum 2 seconds between logs
});

Full Example

const Logger = require("log-vani");

// Create a new Logger instance with full configuration
const logger = new Logger({
  logFile: "logs/app.log",
  rateLimit: 2000, // Log rate limiting in milliseconds
  format: "[{level}] {message} at {timestamp}",
  customTransport: {
    send: function (log) {
      // Send log to an external service
      console.log("Sending log:", log);
    },
  },
});

logger.info("Application started");
logger.warn("This is a warning");
logger.error("An error occurred");
logger.debug("Debugging details");
logger.logAsJson("info", "JSON formatted log entry");
logger.clearLogs();

API

new Logger(options)

Creates a new logger instance.

Options:

  • logFile (string): Path to the log file. Default is test.log.
  • rateLimit (number): Minimum time between log writes in milliseconds. Default is 1000ms.
  • format (string): Custom format for log messages. Placeholders include {level}, {message}, {timestamp}.
  • customTransport (object): An object with a send method for sending logs to external systems.

Methods:

  • info(message): Logs an informational message.
  • warn(message): Logs a warning message.
  • error(message): Logs an error message.
  • debug(message): Logs a debug message.
  • logAsJson(level, message): Logs a message in JSON format.
  • clearLogs(): Clears the log file.

Features

  • Multiple Log Levels: Supports info, warn, error, and debug log levels.
  • Custom Formats: Define custom formats for your log messages.
  • Color-Coded Logs: Terminal output is color-coded for clarity.
  • Custom Transport: Send logs to external systems.
  • JSON Logging: Log entries in JSON format.
  • File-Based Logging: Logs are written to a specified file.
  • Rate Limiting: Prevent excessive log writes in high-frequency scenarios.
  • Clear Logs: Reset the log file when needed.

License

MIT License