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 🙏

© 2024 – Pkg Stats / Ryan Hefner

backtrace-logging

v0.2.2

Published

Hide unnecessary logs until an error occurs

Downloads

13

Readme

backtrace-logging

Hide unnecessary logs¹ until an error² occurs.

Loosely based implementation of http://www.exampler.com/writing/ring-buffer.pdf

  • ¹ console.debug/warn in Browser/Node, util.debug and optionally process.stdout/err in Node.
  • ² window.on(error) in Browser, process.on(uncaughtException, exit) in Node.
  • Auto-register for plug-n-play use, using import.meta.url query strings
  • Customizable API for advanced usage

Install

npm install backtrace-logging

Usage

Just import this in NodeJS and all your console.debug and console.warn logs will be buffered (upto capacity=10) until the end (process.on(error)):

import 'backtrace-logging/node.js'

Or this in the browser with some customizations:

import 'backtrace-logging/browser.js?console=log,debug,warn&capacity=10'

API

Replace …/node.js with …/browser.js accordingly.

Core

import BacktraceLogging from 'backtrace-logging'
const bl = new BacktraceLogging(opts)
  • opts.capacity [number=10] How many messages to buffer
  • opts.queue [Queue] Custom queue for fn-buffer
  • opts.store [Map] Custom map to store { original => patch } function pairs

Patch a function to buffer its calls

bl.fn(fn, opts)
  • fn <function> Function to patch
  • opts [object] options for fn-buffer

Example:

console.log = bl.fn(console.log)

Patch an object's key method with the patched function

bl.object(object, key, opts)
  • object <object> Object to patch
  • key <string> Key to patch in the object
  • opts [object] options for fn-buffer

Example:

bl.object(console, 'log')

Get the original function of the patched function back

bl.get(patch)
  • patch <function> The patched function

Example:

console.log = bl.get(console.log) // restored

Flush the queue

bl.flush()

Register Helper

?auto=false must be passed to disable auto-registration

import { register } from 'backtrace-logging/node.js?auto=false'
register(meta, opts = meta.opts)

Browser/Node

  • meta.console [array=debug,warn] Keys to patch in console
  • opts [object] options for fn-buffer

Node only

  • meta.util [boolean] Patch util.debug
  • meta.process [array] Keys to patch in process (stdout|stderr)
  • meta.file [string] File to append skipped logs to

Auto Register

Requiring …/node.js without ?auto=false calls the register helper function automatically with meta options parsed from import.meta.url.

Pass the values of meta object as a URL query string.

Arrays must be passed as comma-separated values.

import 'backtrace-logging/browser.js?console=log,debug,warn&capacity=10'

Dependencies