Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backtrace-logging

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backtrace-logging

Hide unnecessary logs until an error occurs

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-14.29%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 15 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc