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

console.history

v1.5.2

Published

[![npm](https://img.shields.io/npm/v/console.history.svg)]() [![GitHub release](https://img.shields.io/github/release/lesander/console.history.svg?maxAge=2592000)]() [![npm](https://img.shields.io/npm/dt/console.history.svg)]() [![Code Climate](https://co

Downloads

12,973

Readme

console.history

npm GitHub release npm Code Climate BCH compliancy Build Status

A very small library to store all console logs in console.history.

Usage

Include console-history.js or console-history.min.js in your page or script before any console function gets called. All calls to console.log, console.info, console.warn, console.error and console.debug will be intercepted and stored after doing so. Including every parameter passed to those functions.

Getting Started

This library works in almost all browsers and on any NodeJS server.

Browser

You can download the latest release on GitHub, or use jsDelivr's CDN to get the latest version directly in your browser:

<script src="https://cdn.jsdelivr.net/gh/lesander/[email protected]/console-history.min.js"></script>

See an example entry to the history array below. This example is from the test/test.js file.

{
  "type": "warn",
  "timestamp": "Thu, 01 Sep 2016 15:38:28 GMT",
  "arguments": {
    "0": "Something went wrong, but we're okay!"
  },
  "stack": {
    "0": "at inner (http://localhost:1337/test/test.js:6:11)",
    "1": "at outer (http://localhost:1337/test/test.js:2:3)",
    "2": "at http://localhost:1337/test/test.js:9:1"
  }
}

Server (NodeJS)

Fetch the latest version of console.history:

npm install console.history
require('console.history')
console.log('Hello World!')

At this point, the console.history array is populated with one entry:

[
  {
    type: 'log',
    timestamp: 'Thu, 16 Mar 2017 17:24:25 GMT',
    arguments: { '0': 'Hello World!' },
    stack: [
      'at Console.console._intercept (/.../console.history/test/node.js:4:11)',
      'at Object.<anonymous> (/.../console.history/test/node.js:6:9)',
      'at Module._compile (module.js:571:32)',
      'at Object.Module._extensions..js (module.js:580:10)',
      'at Module.load (module.js:488:32)',
      'at tryModuleLoad (module.js:447:12)',
      'at Function.Module._load (module.js:439:3)',
      'at Module.runMain (module.js:605:10)'
    ]
  }
]

Intercepting the log function

You can add your own middleware to console.history with the function console._intercept(type, args). This can prove useful when you need to access a new log entry before or after it gets logged and added to the history array. See an example below.

console._intercept = function (type, args) {

  if (type === 'error') {
    // send the error to your server or do something else..
  }

  // pass the log intent to the collector.
  console._collect(type, args)
}

Limitations

Every saved console log is stored locally in the array console.history. A page reload will erase all history, as the array is not permanently stored. You could use localStorage or sessionStorage for that.

How it works

This script is basically a man-in-the-middle for all console[log/info/warn/error/debug] functions. Every call gets intercepted, printed and added to the history array.

The code is not that hard to understand, see console-history.js with in-line comments explaining the code.

Contributing

If you'd like to contribute to console.history, or file a bug or feature request, please head over to the issue tracker or open a pull request.

Testing browser-side is as easy as running jekyll serve in the project's directory, navigating to localhost:4000/test in your browser and opening DevTools.

git clone https://github.com/lesander/console.history.git
cd console.history
jekyll serve

License

This software is open-sourced under the MIT License (see the LICENSE file for the full license). So within some limits, you can do with the code whatever you want. However, if you like and/or want to re-use it, I'd really appreciate a reference to this project page.

The software is provided as is. It might work as expected - or not. Just don't blame me.