Git Product home page Git Product logo

patch-console's Introduction

patch-console test

Patch console methods to intercept output

Install

$ npm install patch-console

Usage

import patchConsole from 'patch-console';

const restore = patchConsole((stream, data) => {
	// stream = 'stdout'
	// data = "Hello World"
});

console.log('Hello World');

// Restore original methods
restore();

API

patchConsole(callback)

After this function is called, output from console methods will be intercepted and won't show up in the actual stdout or stderr stream. To restore original console methods and stop intercepting output, call the function which patchConsole() returns.

callback

Type: Function

Function that will be called when output from one of the console methods is intercepted. First argument is name of the stream ("stdout" or "stderr"), second argument is output itself.

Console methods

This module intercepts the following methods:

  • console.assert()
  • console.count()
  • console.countReset()
  • console.debug()
  • console.dir()
  • console.dirxml()
  • console.error()
  • console.group()
  • console.groupCollapsed()
  • console.groupEnd()
  • console.info()
  • console.log()
  • console.table()
  • console.time()
  • console.timeEnd()
  • console.timeLog()
  • console.trace()
  • console.warn()

patch-console's People

Contributors

vadimdemedes avatar

Stargazers

Soon avatar jzone avatar Greg Skiano avatar TED Vortex (Teodor-Eugen Duțulescu) avatar Karl Saehun Chung avatar Helder S Ribeiro avatar Amir Arad avatar Asuka109 avatar Ashley D avatar Kelly Mears avatar Lucas Jones avatar Dario Vladović avatar Hyan Mandian avatar

Watchers

 avatar James Cloos avatar  avatar

patch-console's Issues

Incompatible with Bun

Hi,

I stumbled upon patch-console while debugging a runtime in an ink program error that happens exclusively while running Bun. It appears that using Console with new console.Console(...) is not supported in Bun.

const internalConsole = new console.Console(stdout, stderr);

See /source/index.ts at 8ac1241

It doesn't have much to do with the library, just thought I'd check on and post it this for archiving purpose.

The following issuer addresses this: #3625

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.