Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
filter-console
Advanced tools
The filter-console npm package allows you to filter out unwanted console output in Node.js applications. This can be particularly useful for suppressing noisy logs or warnings that are not relevant to your current debugging or logging needs.
Filter specific messages
This feature allows you to filter out specific messages from the console output. In the example, any console warnings or errors that match the specified patterns will be suppressed.
const filterConsole = require('filter-console');
filterConsole(['Warning: ...', 'Deprecation notice: ...']);
console.log('This will be shown');
console.warn('Warning: This will be filtered');
console.error('Deprecation notice: This will also be filtered');
Filter using regular expressions
This feature allows you to use regular expressions to filter out console messages. This is useful for more complex filtering needs where the exact message may vary.
const filterConsole = require('filter-console');
filterConsole([/Warning: .*/, /Deprecation notice: .*/]);
console.log('This will be shown');
console.warn('Warning: This will be filtered');
console.error('Deprecation notice: This will also be filtered');
Unfilter messages
This feature allows you to temporarily filter messages and then unfilter them when needed. The `unfilter` function restores the original console behavior.
const filterConsole = require('filter-console');
const unfilter = filterConsole(['Warning: ...']);
console.log('This will be shown');
console.warn('Warning: This will be filtered');
unfilter();
console.warn('Warning: This will be shown again');
The console-filter package provides similar functionality by allowing you to filter out unwanted console messages. It offers more customization options for filtering and formatting the console output compared to filter-console.
The console-silencer package allows you to silence specific console methods like log, warn, and error. It is more focused on silencing entire methods rather than filtering specific messages.
The loglevel package provides a simple logging library with support for different log levels (trace, debug, info, warn, error). While it doesn't filter console messages, it allows you to control the verbosity of your logs.
Filter out unwanted
console.log()
output
Can be useful when you don't control the output, for example, filtering out PropType warnings from a third-party React component.
$ npm install filter-console
import filterConsole from 'filter-console';
const disableFilter = filterConsole(['🐼']);
const log = () => {
console.log('');
console.log('🦄');
console.log('🐼');
console.log('🐶');
};
log();
disableFilter();
log();
$ node example.js
🦄
🐶
🦄
🐼
🐶
Returns a function, which when called, disables the filter.
Type: Array<string | RegExp | Function>
Console output that matches any of the given patterns are filtered from being logged. The patterns are matched against what would be logged and not the console
method input arguments directly. Meaning an exclude pattern of 'foo bar'
will match console.log('foo %s', 'bar')
.
Filter types:
string
: Checks if the string pattern is included in the console output.RegExp
: Checks if the RegExp pattern matches the console output.Function
: Receives the console output as a string and is expected to return a truthy/falsy value of whether to exclude it.Type: object
Type: string[]
Default: ['log', 'debug', 'info', 'warn', 'error']
Console methods to filter.
Type: object
Default: console
Use a custom console
object. Can be useful for testing or mocking.
FAQs
Filter out unwanted `console.log()` output
The npm package filter-console receives a total of 112,580 weekly downloads. As such, filter-console popularity was classified as popular.
We found that filter-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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.