Javascript Remove Console Statements

JavaScript: Remove console statements

There are a few tools to remove console statements on your production code. groundskeeper or grunt-remove-logging both let you remove console.* statements, or specify a patter to match your own logger utility. Whith groundskeeper you would do: groundskeeper -n App.logger.log < dirty.js > clean.js There is grunt-groundskeeper task for grunt.

UglifyJS2, which can do much more, but if you are already using it you might want to be aware of this flag:

drop_console -- default false. Pass true to discard calls to console.* functions.

If you use a build tool like grunt, you can use the grunt-contrib-uglify task.

If not, just use sed. sed -i -e '/^\s*console\.log\(.*\);\s*$/d' code.js