
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
patch-console
Advanced tools
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.
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');
The console-log-level package provides a simple logger with log levels. It allows you to control the verbosity of your logs by setting different log levels (e.g., trace, debug, info, warn, error). Unlike patch-console, it does not intercept or modify existing console methods but provides its own logging methods.
Winston is a versatile logging library that supports multiple transports (e.g., console, file, HTTP). It offers more advanced features compared to patch-console, such as log levels, custom formats, and multiple transports. However, it does not focus on intercepting and modifying console output directly.
Log4js is another comprehensive logging library that supports various appenders (e.g., console, file, SMTP). It provides a more structured approach to logging with categories and levels. Similar to winston, it does not intercept console output but offers extensive logging capabilities.
Patch console methods to intercept output
$ npm install patch-console
import patchConsole from 'patch-console';
const restore = patchConsole((stream, data) => {
// stream = 'stdout'
// data = "Hello World"
});
console.log('Hello World');
// Restore original methods
restore();
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.
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.
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()
FAQs
Patch console methods to intercept output
The npm package patch-console receives a total of 569,840 weekly downloads. As such, patch-console popularity was classified as popular.
We found that patch-console demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.