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

investigator

v0.1.1

Published

Interactive and asynchronous logging tool for Node.js. An easier way to log & debug complex requests directly from the command line. Still experimental !

Downloads

6

Readme

investigator

Interactive and asynchronous logging tool for Node.js. An easier way to log & debug complex requests directly from the command line. Still experimental !

investigator

Usage

Nodes

investigator uses a node based logging system. Log nodes (agents) can be nested to help organizing the different steps, synchronous or not, of the process. An agent is defined by its name and can be retrieved at any time in the scope of its parent agent.

investigator-nodes

import {agent} from 'investigator';

const requestAgent = agent('request');
const getUserAgent = requestAgent.child('getUser')
  .log('Retrieving user from db...');

// ...

getUserAgent.success('Done !');
// Or: requestAgent.child('getUser').success('Done !');

Asynchronous logging

async agents are particular nodes which may be resolved or rejected to provide a feedback of their fulfillment.

investigator-async

import {agent} from 'investigator';

const requestAgent = agent('request');

// Creates an async child agent
const getUserAgent = requestAgent.async('getUser')
  .log('Retrieving user from db...');

myAsynchronousFunction().then(() => {
  getUserAgent.resolve('Done !');
}).catch((err) => {
  getUserAgent.reject(err);
});

Inspector

investigator provides an inspector module to allow deep object logging directly in the command line interface, like a browser devtools inspector. It also displays the current stack trace of each log.

investigator-inspector

Installing

Use npm install investigator to install locally. See Usage and API Reference for more information.

Shortcuts

In the command line interface, the following shortcuts are available:

  • Scroll up and down with up arrow, down arrow, or mouse wheel. You may also click on a row to select it.
  • Open Inspecter with i (inspect the currently selected row).
  • Scroll to bottom with b
  • Enable auto-scroll with s. Disable by pressing an arrow key.

Testing & developing

Clone the project with git clone [email protected]:risq/investigator.git.

Install dependencies with npm install.

Launch the example with node examples/index.js.

You can build the project (transpiling to ES5) with npm run build.

TODO (non-exhaustive list)

  • [ ] Log as traditional console.log (or use a multi-transport logging lib like winston), then parse output stream in real time (or from a log file) with investigator.
  • [ ] Improve UI, navigation & controls in the CLI.
  • [ ] Add some performance monitoring.
  • [ ] Improve CLI performance for long time logging (avoid memory leaks).

API Reference

Investigator

investigator.agent(String name [, data]) -> Agent

Creates a new root agent, with a given name. Data parameters of any type can also be passed to be logged into the command line interface.

import {agent} from 'investigator';

onRequest(req, res) {
  const requestAgent = agent('request', req.id, req.url);
}

Agent

agent.log(data [, data]) -> Agent

Log passed data parameters under the given agent node. Returns the same agent (so it can be chained).

import {agent} from 'investigator';

onRequest(req, res) {
  const requestAgent = agent('request', req.id, req.url);
  requestAgent.log('Hello')
    .log('World');
}
agent.success(data [, data]) -> Agent

Log passed data parameters under the given agent node, as a success (displayed in green). Returns the same agent (so it can be chained).

agent.warn(data [, data]) -> Agent

Log passed data parameters under the given agent node, as a warning (displayed in yellow). Returns the same agent (so it can be chained).

agent.error(data [, data]) -> Agent

Log passed data parameters under the given agent node, as an error (displayed in red). Returns the same agent (so it can be chained).

agent.child(name [, data]) -> Agent

Returns a child of the current agent, defined by its name. If a child with the given name already exists on the agent, it will be returned. If not, it will be created.

Data objects can be passed as parameters and will be logged on the child's context.

import {agent} from 'investigator';

onRequest(req, res) {
  const requestAgent = agent('request', req.id, req.url);

  if (req.url === '/user/login') {
    requestAgent.child('login', 'Logging in...');

    if (validate(req.user, req.password)) {
      requestAgent.child('login')
        .success('Login data validated !');
    } else {
      requestAgent.child('login')
        .error('Error validating user data.')
    }
  }
}
agent.async(name [, data]) -> Agent

Returns a asynchronous child of the current agent, defined by its name. If a child with the given name already exists on the agent, it will be returned. If not, it will be created.

Data objects can be passed as parameters and will be logged on the child's context.

An async agent has .resolve() and .reject() methods, to keep track of its fulfillment.

import {agent} from 'investigator';

onRequest(req, res) {
  const requestAgent = agent('request', req.id, req.url);

  if (req.url === '/user/login') {
    requestAgent.child('login', 'Logging in...');

    authUser(req.user, req.password).then(() => {
      requestAgent.child('login')
        .success('Authentication succeeded !');
    }).catch((err) => {
      requestAgent.child('login')
        .error('Error validating user data.')
    });
  }
}
agent.resolve(data [, data]) -> Agent

Resolves an async agent. Log data parameters under the given agent node, as a success. Returns the same agent (so it can be chained).

An async agent can only be resolvded or rejected once.

agent.reject(data [, data]) -> Agent

Resolves an async agent. Log data parameters under the given agent node, as an error. Returns the same agent (so it can be chained).

An async agent can only be resolvded or rejected once.

Contributing

Feel free to contribute ! Issues and pull requests are highly welcomed and appreciated.

License

The MIT License (MIT)

Copyright (c) 2015 Valentin Ledrapier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.