Filter out unwanted `console.log()` output
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
const filterConsole = require('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
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
consolemethod 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:
Array
['log', 'debug', 'info', 'warn', 'error']
Console methods to filter.
Type:
Object
console
Use a custom
consoleobject. Can be useful for testing or mocking.
MIT © Sindre Sorhus