最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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(){}
发布评论

评论列表(0)

  1. 暂无评论