silentConsole
Globally overwrite console methods - silence all, filter individually.
Motivation
Just debugging a legacy project and I had too many logs / warnings printing to the console. I started to remove / comment them, but realized they could be useful later on. This module is just an extension of the code I wrote for that use.
Usage
Install
npm install --save-dev silentconsole
How to Implement
You can use it at the file level, but it is best for importing at top level (usually your main entry ie index.js) and using for global silencing / filtering of console output.
Globally silence console.log and console.warn
;;; console; // will not print to consoleconsole; // will not print to consoleconsole; // will print 'foo' to console
Globally filter console.log and console.warn with filter method as second argument to silentConsole
;;; console; // will print 'foo' to consoleconsole; // will not print to console console; // will print 'foo bar' to consoleconsole; // will not print to console
Globally silence console.log, but allow it for single instances
original
will be added to the console object storing all of the original methods of console.
;; console; // will not print to consoleconsole; // will not print to console consoleoriginal; // will print 'foo' to console
Globally set as false, restore to make further statements work
This is not a great good use.
Either call method again with no 2nd parameter
; ;console; // will not print to consoleconsole; // will not print to console ;console; // will print 'foo' to consoleconsole; // will print 'bar' to console
Or call method again with 2nd parameter false as in, do not override log.
; ;console; // will not print to consoleconsole; // will not print to console ;console; // will print 'foo' to consoleconsole; // will print 'bar' to console
Prints all arguments passed like a standard console method
Even if you setup the silentConsole, you can still pass in multiple arguments. The printed results will be a bit different depending on what you pass as last argument.
;; console; // will print 'foo bar baz' to consoleconsole; // will print 'foo bar' to console
Author
Steve Reed |