All Projects → risq → Investigator

risq / Investigator

Licence: mit
Interactive and asynchronous logging tool for Node.js. An easier way to log & debug complex requests directly from the command line (experimental).

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Investigator

Mongotail
Command line tool to log all MongoDB queries in a "tail"able way
Stars: ✭ 169 (+9.03%)
Mutual labels:  command-line-tool, cli, logging
Wufei
Async Kuberenetes Namespace Log Recorder / Streamer
Stars: ✭ 27 (-82.58%)
Mutual labels:  cli, async, logging
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-73.55%)
Mutual labels:  cli, logging, debug
Elixir cli spinners
Spinnig Animations for Command Line Applications
Stars: ✭ 117 (-24.52%)
Mutual labels:  command-line-tool, cli
Droid
A command-line tool for checking Android OS version history written by Rust.
Stars: ✭ 115 (-25.81%)
Mutual labels:  command-line-tool, cli
Zoya
Truly highly composable logging utility
Stars: ✭ 116 (-25.16%)
Mutual labels:  cli, logging
Awesome Cli
A curated list of awesome resources for building immersive CLI experiences.
Stars: ✭ 104 (-32.9%)
Mutual labels:  command-line-tool, cli
Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (-18.71%)
Mutual labels:  command-line-tool, cli
Freenom Dns Updater
A tool to update freenom's dns records
Stars: ✭ 117 (-24.52%)
Mutual labels:  command-line-tool, cli
Check It Out
A command line interface for Git Checkout. See branches available for checkout.
Stars: ✭ 127 (-18.06%)
Mutual labels:  command-line-tool, cli
Git Tidy
Tidy up stale git branches.
Stars: ✭ 137 (-11.61%)
Mutual labels:  command-line-tool, cli
Git Chglog
CHANGELOG generator implemented in Go (Golang).
Stars: ✭ 1,895 (+1122.58%)
Mutual labels:  command-line-tool, cli
N26
API and CLI to get information of your N26 account
Stars: ✭ 107 (-30.97%)
Mutual labels:  command-line-tool, cli
Python N26
💵 Unofficial Python client for n26 (Number 26) - https://n26.com/
Stars: ✭ 116 (-25.16%)
Mutual labels:  command-line-tool, cli
Cli.fan
Blog about notable commandline tools
Stars: ✭ 106 (-31.61%)
Mutual labels:  command-line-tool, cli
Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (-18.71%)
Mutual labels:  command-line-tool, cli
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-14.84%)
Mutual labels:  logging, debug
Brotab
Control your browser's tabs from the command line
Stars: ✭ 137 (-11.61%)
Mutual labels:  command-line-tool, cli
Aptos
☀️ A tool for validating data using JSON Schema and converting JSON Schema documents into different data-interchange formats
Stars: ✭ 144 (-7.1%)
Mutual labels:  command-line-tool, cli
Ask Cli
Alexa Skills Kit Command Line Interface
Stars: ✭ 100 (-35.48%)
Mutual labels:  command-line-tool, cli

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 Inspector 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).
  • [ ] Allow client-side logging via WebSockets.

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 resolved 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 resolved 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].