New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

patch-console

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

patch-console

Patch console methods to intercept output

2.0.0
latest
Source
npm
Version published
Weekly downloads
749K
-19.15%
Maintainers
1
Weekly downloads
 
Created

What is patch-console?

The patch-console npm package allows you to intercept and modify console output in Node.js applications. This can be useful for logging, debugging, or filtering out unwanted console messages.

What are patch-console's main functionalities?

Intercepting console output

This feature allows you to intercept and modify console output. In this example, any message sent to stdout is prefixed with 'Modified: '.

const patchConsole = require('patch-console');

patchConsole((stream, data) => {
  if (stream === 'stdout') {
    return `Modified: ${data}`;
  }
  return data;
});

console.log('This is a test');

Filtering console output

This feature allows you to filter out specific console messages. In this example, any message containing the word 'ignore' will not be shown in the console.

const patchConsole = require('patch-console');

patchConsole((stream, data) => {
  if (data.includes('ignore')) {
    return '';
  }
  return data;
});

console.log('This message will be shown');
console.log('This message will be ignored');

Logging to a file

This feature allows you to log console messages to a file. In this example, all console messages are written to 'log.txt'.

const fs = require('fs');
const patchConsole = require('patch-console');

const logStream = fs.createWriteStream('log.txt', { flags: 'a' });

patchConsole((stream, data) => {
  logStream.write(data);
  return data;
});

console.log('This message will be logged to a file');

Other packages similar to patch-console

Keywords

stdout

FAQs

Package last updated on 04 Feb 2022

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