JavaScript - quickly hide all console.log
Simple and easy, put this code at the beginning of your code:
console.log = function(){};
All the console messages will magically disappear...
Happy Hacking!
Written by Mariz Melo
Related protips
8 Responses

I've seen a bunch of these and similar tips for hiding console.log
in production but how is console.log getting to production anyway? I've never seen a reason to use console.log over proper breakpoint debugging which requires no code to be turned on/off in production or code at all for that matter. console.log
, to me, seems like just a less obtrusive alert()

@shawncplus has a point, another approach is if you use jslint and CI then make a rule that will ensure that no console.log gets into production (or commited in your main repo).

@shawncplus I agree for client-side code, but on my NodeJS code this is really useful.


@shawncplus isn't this for debug mode? I am running in production and don't wanna see the console.log messages from other developers.

Surely there's a more robust logging solution one could use in production over console.log? That is unless you're implying that you're coding on live.

That can cause an error if console
isn't defined (when IE has dev tools closed). If you wanted to kill it safely, you should do…
var console = {};
console.log = function(){};
Though, really, you probably ought to probably be doing something like this…

Bah, somehow GitHub mangled the gist I was trying to link to. Here goes again…