Giter Site home page Giter Site logo

console-monkey-patch's Introduction

Build Status

console-monkey-patch

Hack the console object methods (like log, error, info etc.).

Abstract

In Node.js it is sometime desirable to redirect console.log & Co. calls to a given stream but not possible to actually replace stdout and/or stderr. This module allow to override console methods in a simple way.

Installation

npm install console-monkey-patch

Simple example

The most simple example is to create a new console.Console object (see https://nodejs.org/api/console.html#console_class_console):

var fs = require("fs");
var newstdout = fs.createWriteStream('/tmp/stdout.log', {flags: 'a'});
var newstderr = fs.createWriteStream('/tmp/stderr.log', {flags: 'a'});
var newcons   = new console.Console(newstdout, newstderr);

require("console-monkey-patch")(newcons);

console.log('this should go to /tmp/stdout.log');
console.error('this should go to /tmp/stderr.log');

Limitations

The module only override the console methods documented at https://nodejs.org/api/console.html and does not replace process.stdout and process.stderr. As a result, code (including modules) using directly theses streams won't be "affected".

LICENSE

MIT, see MIT-LICENSE.

console-monkey-patch's People

Contributors

kaworu avatar

Watchers

 avatar Alain Pellaux avatar James Cloos avatar  avatar RedSonic avatar Jonas Luthi avatar  avatar

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.