×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Isaac Dettman
Added: Nov 23, 2016 6:28 PM
Views: 8
Replace the console api to handle/disable console logging
  1. Object.defineProperty(window, "console", {
  2.     value: console,
  3.     writable: false,
  4.     configurable: false
  5. });
  6.  
  7. var i = 0;
  8. function showWarningAndThrow() {
  9.     if (!i) {
  10.         setTimeout(function () {
  11.             console.log("%cWarning message", "font: 2em sans-serif; color: yellow; background-color: red;");
  12.         }, 1);
  13.         i = 1;
  14.     }
  15.     throw "Console is disabled";
  16. }
  17.  
  18. var l, n = {
  19.         set: function (o) {
  20.             l = o;
  21.         },
  22.         get: function () {
  23.             showWarningAndThrow();
  24.             return l;
  25.         }
  26.     };
  27. Object.defineProperty(console, "_commandLineAPI", n);
  28. Object.defineProperty(console, "__commandLineAPI", n);