DEV Community

Discussion on: Say Goodbye to console.log from Production environment

Collapse
 
milmike profile image
MilMike • Edited

I do this too but without a plugin, I simply set an empty function for console.log on prod env.

console.log = function(){}
Enter fullscreen mode Exit fullscreen mode

beside console sometimes people also use alert to test something. In some of our webapps we disabled alert the same way like above.. (someone once pushed alert("curse word") on friday in production, it popped up when user did something special. We got interesting mails on monday... ;)

Collapse
 
lionelrowe profile image
lionel-rowe

That's annoying as hell for anyone developing downstream code (browser extensions etc.) to be compatible with your site/web app. Much better to use lint rules or an approach like the one mentioned in this article.

Collapse
 
gulshanaggarwal profile image
Gulshan Aggarwal

Suggestions are always welcome, keep it up. 👍

Collapse
 
gulshanaggarwal profile image
Gulshan Aggarwal

nice! approach I'm gonna try it next time 👌

Collapse
 
pengeszikra profile image
Peter Vivo

consol.log harming by the way when client assign her own function to grab information

window.console.log = grabLogEntries
Enter fullscreen mode Exit fullscreen mode

with overwrite our cleaning in client side.

Collapse
 
etiennejcharles profile image
Etienne-Joseph Charles

Just curiously, wouldn't that that prevent from errors beings logged if ever you're using something like Sentry or DataDog or NewRelic to log errors ?

Collapse
 
visualjeff profile image
Jeff

What about?

globalThis.console = { log: () => {} };

Collapse
 
reduardo7 profile image
Eduardo Cuomo

What will happen when I use console.info() for example?

Thread Thread
 
visualjeff profile image
Jeff • Edited

Calling info() will cause an exception.

So a better approach would be to do the following if you are only interested in silencing console.log:

globalThis.console.log = () => {};
Enter fullscreen mode Exit fullscreen mode

It's helpful you called this out.

Collapse
 
hyerim profile image
Hyerim

Wow Im newbie and wanna know how I can use this.
type just like normal console.log()?

Thread Thread
 
gulshanaggarwal profile image
Gulshan Aggarwal

Welcome! keep learning & chill 😎