javascript - How to disablehide console logs in production? - Stack Overflow

I am using cordova to build my app. I want to hide all logs created by console.log in production app.

I am using cordova to build my app. I want to hide all logs created by console.log in production app. But I could not find any solution to disable it.

Is this really possible to hide console logs ?

I'll really appreciate any contribution.

Thanks Regards

I am using cordova to build my app. I want to hide all logs created by console.log in production app. But I could not find any solution to disable it.

Is this really possible to hide console logs ?

I'll really appreciate any contribution.

Thanks Regards

Share Improve this question edited Jun 17, 2016 at 15:45 user177800 asked Jun 17, 2016 at 15:40 user2899728user2899728 2,3194 gold badges18 silver badges28 bronze badges 4
  • 2 console.log is plain JS, nothing to do with Cordova or Ionic. – C14L Commented Jun 17, 2016 at 15:42
  • yes I know but I used thousands of console.log(); I am using it for debugging purpose. I don't want to remove all those so that I can re-use them in future to debug any issue. But for now I just want some way to hide all of those logs instead of removing lines manually. – user2899728 Commented Jun 17, 2016 at 15:43
  • 1 I wrote my own Logger class, which allows me to set a level for debugging messages and enable/disable it. That way, I only go through my Logger layer and avoid console.log being used directly. That said, for simplicity, you could just override the console.log function with an empty function block, as described by C14L below. If the console isn't being displayed, then it's not really going to do any massive harm to leave those log statements in there. It may help you debug production problems to at least have SOME console.log statements remaining. Or remove them prior to release. Up to you. – ManoDestra Commented Jun 17, 2016 at 15:50
  • 1 Are you minifying your code for production? This should strip out any console.logs – Geraint Commented Jun 17, 2016 at 15:57
Add a ment  | 

1 Answer 1

Reset to default 6

You could just override the log method of the console object.

console.log = function(){}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745085127a4610361.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信