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* @param* @return */console { if'warn' 'error' > -1 return args; return undefined;}
// Add red CSS color to error logconsole { iflevel === 'error' && argslength > 0 args0 = '%c' + args0; args; return args; }