Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling console.log() in production

I have run the following to disable console logs for production environments in my angular application. The below code works as expected for chrome, however, it still shows logs in IE 11.

main.ts

if (environment.production) {
  enableProdMode();
if(window){
  window.console.log=function(){};
 }
}

Is this a polyfill issue? I wasn't able to find anything online about it.

EDIT

This question may seem similar but does not address my issue as to why overriding the console log function to a blank method works in chrome but not IE 11.

like image 507
R2B Boondocks Avatar asked Dec 05 '22 10:12

R2B Boondocks


1 Answers

Solution is to add the polyfill to your polyfill.ts file

if(!window.console) {
 var console = {
  log : function(){},
  warn : function(){},
  error : function(){},
  time : function(){},
  timeEnd : function(){}
 }
}
like image 60
R2B Boondocks Avatar answered Dec 09 '22 14:12

R2B Boondocks