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-capture

v1.0.3

Published

Intercept console methods

Readme

log-capture

A lightweight JavaScript library for intercepting browser console methods. My first npm package 😅☺️

Installation

pnpm add log-capture

Or with npm:

npm install log-capture

Quick Start

import { capture } from 'log-capture'

capture.on('log', (original, ...args) => {
    // Handle the intercepted log
    original(...args)
})

capture.start()

console.log('Hello world')

The original console methods are preserved and can be called through the original function provided to each listener.

Use Cases

log-capture can be used as a foundation for different console-related features, such as:

  • Remote logging — send browser logs and errors to a remote server for monitoring and debugging.
  • Visual console — display console messages directly inside the application's DOM, useful for dashboards, development tools, and embedded applications.
  • Hide logs — prevent selected logs, warnings, or errors from being displayed in the browser console.
  • Log filtering — filter messages based on their method, content, or custom application rules.
  • Error monitoring — collect errors and warnings and send them to an external monitoring service.
  • Custom logging — transform or process console messages before passing them to the original console method.

Supported Methods

log-capture currently intercepts:

  • log
  • warn
  • table
  • clear
  • debug
  • error

Listening to Console Methods

Use on() to add one or more listeners.

capture.on('error', (original, ...args) => {
    saveError(args)

    original(...args)
})

Multiple listeners can be registered for the same method:

capture.on('log', listener1, listener2)

Important

Do not call an intercepted console method inside a listener:

// Do not do this
capture.on('log', (...args) => {
    console.log(...args)
})

This can cause an infinite interception loop.

If you want to keep the original console behavior, use the original function:

capture.on('log', (original, ...args) => {
    saveLog(args)

    original(...args)
})

Removing Listeners

Use off() to remove specific listeners:

const handleError = (original, ...args) => {
    saveError(args)
    original(...args)
}

capture.on('error', handleError)

capture.off('error', handleError)

To remove all listeners for a method:

capture.off('error')

Start and Stop

Start interception with start():

capture.start()

Stop interception with stop():

capture.stop()

When stopped, the original console methods are restored.

EventListener Aliases

addEventListener() and removeEventListener() are aliases for on() and off().

capture.addEventListener('warn', handleWarning)

capture.removeEventListener('warn', handleWarning)

Checking the Capture State

Use isCapturing to check whether interception is active:

if (capture.isCapturing) {
    // Capture is active
}

Registered listeners are available through listeners:

console.log(capture.listeners)

License

MIT

Enjoy, peace and love 😇✌️☺️​