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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cnips/simplelog

v1.0.0

Published

A lightweight, flexible logging library for TypeScript/JavaScript applications with support for multiple log levels and printf-style formatting. This logger is mainly for use in CNIPS componenets using javascript/typescript.

Readme

TypeScript Logger

A lightweight, flexible logging library for TypeScript/JavaScript applications with support for multiple log levels and printf-style formatting. This logger is mainly for use in CNIPS componenets using javascript/typescript.

CommonJS is not supported, this library is designed to be used with ES modules.

Features

  • 🎯 Multiple Log Levels: Debug, Info, Warn, and Error
  • 📝 Printf-style Formatting: Use format strings with arguments
  • 🏷️ Application Tagging: Tag logs with application/component names
  • Automatic Timestamps: ISO 8601 formatted timestamps
  • 💾 In-Memory Storage: Collect and retrieve logs programmatically
  • 🎛️ Level Filtering: Only log messages at or above the configured level

Installation

npm install @cnips/logger

Quick Start

import { Logger, levels } from "@cnips/logger";

// Create a logger instance
const logger = new Logger("MyApp", levels.info);

// Log messages at different levels
logger.info("Application started");
logger.warn("This is a warning");
logger.error("Something went wrong");
logger.debug("Debug info"); // Won't be logged (below info level)

API Reference

Logger Class

Constructor

new Logger(app: string, level?: number)
  • app: Application or component name (appears in log messages)
  • level: Minimum log level (defaults to levels.info)

Methods

info(message: string, ...args: any[]): void

Logs an informational message.

logger.info("User %s logged in at %s", username, new Date().toISOString());
warn(message: string, ...args: any[]): void

Logs a warning message.

logger.warn("Low disk space: %d%% remaining", diskUsage);
error(message: string, ...args: any[]): void

Logs an error message.

logger.error("Failed to connect to database: %s", error.message);
debug(message: string, ...args: any[]): void

Logs a debug message.

logger.debug("Processing request with ID: %s", requestId);
getLogs(): string[]

Returns all logged messages as an array of strings.

const allLogs = logger.getLogs();
console.log(allLogs);
clearLogs(): void

Clears all stored log messages.

logger.clearLogs();
string(): string

Returns all logs as a single newline-separated string.

const logString = logger.string();
console.log(logString);

Log Levels

export const levels = {
    debug: -1,  // Most verbose
    info: 0,    // Default level
    warn: 1,    // Warnings only
    error: 2    // Errors only
}

Usage Examples

Basic Logging

import { Logger, levels } from "@cnips/logger";

const logger = new Logger("WebServer", levels.debug);

logger.debug("Server configuration loaded");
logger.info("Server starting on port 3000");
logger.warn("High memory usage detected");
logger.error("Failed to connect to database");

Printf-style Formatting

const logger = new Logger("UserService");

const userId = 12345;
const action = "login";
const timestamp = new Date().toISOString();

logger.info("User %d performed action '%s' at %s", userId, action, timestamp);
// Output: 2025-06-30T10:30:45.123Z [UserService] INFO User 12345 performed action 'login' at 2025-06-30T10:30:45.123Z

Log Level Filtering

// Only log warnings and errors
const logger = new Logger("CriticalService", levels.warn);

logger.debug("Debug message");  // Won't be logged
logger.info("Info message");    // Won't be logged  
logger.warn("Warning message"); // Will be logged
logger.error("Error message");  // Will be logged

Collecting and Processing Logs

const logger = new Logger("DataProcessor");

// Perform some operations
logger.info("Processing started");
logger.warn("Found %d invalid records", 5);
logger.info("Processing completed");

// Get all logs
const logs = logger.getLogs();
logs.forEach(log => console.log(log));

// Get logs as a single string
const logOutput = logger.string();
console.log(logOutput);

// Clear logs for next batch
logger.clearLogs();

Log Format

Each log message follows this format:

YYYY-MM-DDTHH:mm:ss.sssZ [AppName] LEVEL Message

Example:

2025-06-30T14:30:45.123Z [MyApp] INFO User authentication successful
2025-06-30T14:30:46.456Z [MyApp] WARN Rate limit approaching for user 12345
2025-06-30T14:30:47.789Z [MyApp] ERROR Database connection failed

TypeScript Support

This library is written in TypeScript and includes full type definitions. No additional @types packages are needed.