console-blame

1.1.3 • Public • Published

console-blame

NPM Version Build Status Coverage Status Dependency Status

It highlights and helps to find forgotten console.log calls in runtime. Live example

Installation

console-blame can be installed using npm:

npm install console-blame --save-dev

Interface

  • ConsoleBlame(Object consoleObject, String[] trapsList)
  • ConsoleBlame(Object consoleObject)
  • ConsoleBlame(String[] trapsList)
  • ConsoleBlame()
  • ConsoleBlame#configure(Object options) see Configuration options
  • ConsoleBlame#restore() releases all trapped methods
  • ConsoleBlame#trap(String[] ...methods) traps all listed methods
  • ConsoleBlame#trap() traps all available methods

Configuration options

Can be configured, using require('console-blame').configure({ ... })

  • pathFormat format of file name, line and column. default: '%s:%d:%d'
  • lineFormat format of code line. default: '%d | %s'
  • contextSize number of lines before and after target line. default: 3
  • sources print source code? default: true

Example

Trap all methods of console

require('console-blame')();
 
console.log(123); // Will print debug message
console.error(123); // Will print debug message

Trap only console.log

require('console-blame')(['log']);
 
console.log(123); // Will print debug message

Trap only log and error of specific console object

require('console-blame')(console, ['log', 'error']);
 
console.log(123); // Will print debug message

Trap all methods and change size of context and line format

require('console-blame')().configure({
   contextSize: 5,
   lineFormat: '%d\t%s'
});
 
console.log(123);

Restore traps

var blame = require('console-blame')();
console.log(123); // Will print debug message
blame.restore();
console.log(123); // Will NOT print debug message
blame.trap();
console.log(123); // Will print debug message

Output example

A log message
/home/username/projects/console-blame/lib/index.js:174:9
 169 | attachTrapsTo(console).configure({
 170 |   contextSize: 5,
 171 |   lineFormat: '%d\t%s'
 172 | });
 173 |
 174 | console.log('A log message'); // <<< This line will be highlighted
 175 |

Package Sidebar

Install

npm i console-blame

Weekly Downloads

0

Version

1.1.3

License

none

Last publish

Collaborators

  • azproduction