🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

console-filterify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-filterify

Browserify transform that wraps all `console.*` calls in a filtering function that can be changed live directly in the browser.

1.0.0
latest
npm
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

console-filterify

Browserify transform that wraps all console.* calls in a filtering function that can be changed live directly in the browser.

If console.filterify is defined, it will be called with the console method (such as log, warn, error, dir) as first argument and the original console arguments as an array as the second argument.

This function is assumed to return either an array to log - possibly with manipulated values - or undefined to ignore logging this line at all.

If console.filterify does not exist, the wrapper logs as usual.

Purpose

The usual approach to filtering or coloring or decorating loggers are to have a wrapping library, which usually loses important information such as line and file name. This is not necessarily that much better, but offers a way to keep that kind of information as well as filter and/or manipulate the logging data dynamically on the way.

Examples

/**
* @param {string} level The log level such as log, warn error etc
* @param {array} args   Array of original arguments
* @return {array} of arguments, possibly modified, or undefined to silence this log line 
*/
console.filterify = function(level, args) {
    if(['warn', 'error'].indexOf(level) > -1) {
        return args;
    }
    return undefined;
}
// Add red CSS color to error log
console.filterify = function(level, args) {
    if(level === 'error' && args.length > 0) {
        args[0] = '%c' + args[0];
        args.splice(1, 0, 'color:red');
    }
    return args;    
}

Keywords

console

FAQs

Package last updated on 13 Nov 2017

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