Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable console.log() on production and display a banner?

Tags:

Can anyone shed some light on how to disable console.log() on production? I have seen achievements as below:

enter image description here

enter image description here

like image 804
Haifeng Zhang Avatar asked Sep 22 '18 04:09

Haifeng Zhang


People also ask

How do I disable console logging?

To stop the console logging, use the no logging console global configuration command (highly recommended for routers that are not usually accessed through the console port) or you might want to limit the amount of messages sent to the console with the logging console level configuration command (for example, logging ...

How do I disable the console on my website?

To disable Javascript console, we need to throw an exception in the get accessor by checking if the property attached by chrome developer tool exists. With this script above, user won't be allowed to enter Javascript in the console. It also blocks auto-complete in console too. Thank you friends!

How do I turn off console warnings in react?

The Yellow warning box in React Native can be both helpful and annoying. There are many errors that can be ignored but end up blocking necessary pieces of the application. To disable the yellow box place console. disableYellowBox = true; anywhere in your application.


1 Answers

Are you using some kind of module bundler ? In webpack you have option to drop_console in build. What drop console does is remove all console.log statements from your code. There is also npm module for same please take a look. https://www.npmjs.com/package/babel-plugin-transform-remove-console This is a bagel plugin and if you have babel setup you can use it.

If all this doesn't meet your requirements. You can simply override console.log statement or use custom logger as other answers have suggested.

like image 63
Shubham Gupta Avatar answered Sep 28 '22 19:09

Shubham Gupta