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

get-logs-test

v0.1.8

Published

A template for creating publishable JS packages with TypeScript, testing, and Next.js integration

Readme

Logs MCP - Singleton Console Logger

A singleton console log collector that works across multiple bundles in the browser. It intercepts all console methods and stores logs in memory for later retrieval.

Features

  • True Singleton: Uses window object to ensure only one instance exists across all bundles
  • Auto-capture: Intercepts console.log, console.warn, console.error, console.info, and console.debug
  • Memory efficient: Configurable maximum log entries with FIFO rotation
  • Cross-bundle: Multiple bundles can use the same logger instance
  • Type-safe: Full TypeScript support

Installation

npm install logs-mcp

Usage

Basic Usage

import { init, getLogs, getLogsAsString } from 'logs-mcp/browser'

// Initialize the singleton logger (safe to call multiple times)
init({ maxLogs: 1000 })

// Your console logs are now being captured
console.log('Hello world')
console.error('An error occurred', new Error('Test error'))

// Get all logs as array
const logs = getLogs()
// Output: [{ level: 'log', message: ['Hello world'], timestamp: 1234567890 }, ...]

// Get logs as formatted string
const logsString = getLogsAsString()
// Output: "[2024-01-01T00:00:00.000Z] [LOG] Hello world\n[2024-01-01T00:00:00.001Z] [ERROR] An error occurred..."

Singleton Behavior

The logger is a true singleton - multiple imports or bundles will share the same instance:

// bundle1.js
import { init } from 'logs-mcp/browser'
init({ maxLogs: 500 })

// bundle2.js
import { init, getLogs } from 'logs-mcp/browser'
init({ maxLogs: 1000 }) // This won't create a new instance, just returns existing one

// Both bundles share the same logs
const allLogs = getLogs() // Contains logs from both bundles

API Reference

init(options?: { maxLogs?: number })

Initialize the singleton logger. Safe to call multiple times.

  • maxLogs: Maximum number of log entries to keep (default: 1000)

getLogsCollector()

Get the singleton ConsoleLogCollector instance. Creates one if it doesn't exist.

getLogs(): LogEntry[]

Get all captured logs as an array.

getLogsAsString(): string

Get all logs formatted as a string with timestamps.

getLogsByLevel(level: 'log' | 'warn' | 'error' | 'info' | 'debug'): LogEntry[]

Get logs filtered by level.

clearLogs()

Clear all captured logs.

stop()

Stop capturing logs and restore original console methods.

isInitialized(): boolean

Check if the logger is currently initialized and capturing.

LogEntry Interface

interface LogEntry {
  level: 'log' | 'warn' | 'error' | 'info' | 'debug'
  message: any[]
  timestamp: number
  stack?: string // Present for errors
}

Advanced Usage

Using the ConsoleLogCollector directly

For more control, you can use the ConsoleLogCollector class directly:

import { ConsoleLogCollector, createConsoleLogCollector } from 'logs-mcp/browser'

// Create your own instance (not singleton)
const collector = createConsoleLogCollector({ maxLogs: 500 })
collector.start()

// Use console methods as normal
console.log('Test message')

// Get logs
const logs = collector.getLogs()

// Stop collecting
collector.stop()

Use Cases

  • Error Reporting: Capture console logs to include with error reports
  • Debugging: Access console history in production environments
  • Testing: Verify console output in tests
  • Monitoring: Track warnings and errors across your application
  • Multi-bundle Apps: Share logs across micro-frontends or lazy-loaded modules

Browser Support

Works in all modern browsers that support ES6+ features.

Development

Scripts

  • pnpm dev - Start development mode with watch
  • pnpm build - Build the package
  • pnpm test - Run all tests
  • pnpm typecheck - Run TypeScript type checking
  • pnpm lint - Run ESLint
  • pnpm format - Format code with Prettier
  • pnpm pub --name <name> - Publish package to npm

License

MIT