An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
Hide all console logs in production with just 3 lines of code
We basically use the console.log() in our JS application to check wether our code is working properly or to replicate the bug or issue in the app. without the logs it is very time consuming and difficult to find the problem.
But these logs are meant for the developer only and you don't want to show these to the end users so we have to remove the console statement or to comment that.
Before i know this stuff i was commenting all the console.logs in my application and deploying the app on the live server. so the console's are not visible to the users
How I hide all the consoles
if (env === 'production') { console.log = function () {};}
Here we are overriding the default console.log function with the new one which was returing nothing. Here we have added the environment check to override console function only if the environment is production. if you don't have environment variable then you can jsut simply do.
console.log = function () {};
I am using this on my live app to hides the console. If someone know any other method or any disadvantage of using this one. plz leave your comment.
To keep up with everything Im doing, follow me on Twitter. I am posting these hacks and tricks there also ==> Kushal Sharma
Original Link: https://dev.to/sharmakushal/hide-all-console-logs-in-production-with-just-3-lines-of-code-pp4
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To