Socket
Book a DemoInstallSign in
Socket

console-monkey-patch

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-monkey-patch

Node.js module monkeypatching the console object

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
24
-47.83%
Maintainers
2
Weekly downloads
 
Created
Source

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.

Keywords

console

FAQs

Package last updated on 01 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.