Git Product home page Git Product logo

console-hook's Introduction

Console Hook

Hook into the console for transparent log recording in production and log capture for testing.

npm install console-hook

Works in the browser too, just grab console-hook/index.js.

Examples

Intercept all console method calls

var Hook = require('console-hook');
var myHook = Hook().attach((method, args) => {
  // method is the console[method] string
  // args is the arguments object passed to console[method]
});

// okay, we're done playing with the console stuffs
myHook.detach();

Intercept all console method calls and don't call console

var Hook = require('console-hook');
var silence = true; // could be `isProduction`
var myHook = Hook(console, silence).attach((method, args) => {
  // method is the console[method] string
  // args is the arguments object passed to console[method]
});

// okay, we're done playing with the console stuffs
myHook.detach();

Intercept only console.error calls

var Hook = require('console-hook');
var myHook = Hook().attach('error', (method, args) => {
  // method is the console[method] string, always "error"
  // args is the arguments object passed to console[method]
});

// okay, we're done playing with the console stuffs
myHook.detach();

Use another console-like Logger

// if you have an Ember app and already use Ember.Logger
var Hook = require('console-hook');
var myHook = Hook(Ember.Logger).attach((method, args) => {
  // method is the console[method] string
  // args is the arguments object passed to console[method]
});

// okay, we're done playing with the console stuffs
myHook.detach();

Contributing

Contributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core assert module.

# running tests
npm run test

Follow me on Twitter for updates or just for the lolz and please check out my other repositories if I have earned it. I thank you for reading.

console-hook's People

Contributors

andrejewski avatar evantorrie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

evantorrie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.