How to disable console.log for a particular js file?

Asked

Viewed 319 times

2

I have many commands console.log in an archive regras.js. I wonder if there’s a way console.log only in this file, since commenting each console.log would be very time consuming, as it has many.

Remarks:

I’ve used that resource:

But it doesn’t suit me since it disables the console.log of all files.

console.log = Function() {}

  • 5

    Comments on all console.log with a replace all from Notepad++.. in less than 10 seconds you do this

  • 1

    console.log is not break point type that you can toggle all to disable/enable you can use some text editor to search for and replace these occurrences if you do console.log replace //console.log everything will be commented.

3 answers

4

At the beginning of your file do:

var __log = console.log;
console.log = function() {};

And at the end of it restore console.log with:

console.log = __log;

3


Add to the end of your file regras.js the following line:

console.clear();

This will clear all the console.log() executed. Can be a good solution if you do not want or can not comment all lines.

0

Programmatically, I don’t know a way.

But using the replace all of any IDE is possible. Search for console.log and replace with //console.log

Browser other questions tagged

You are not signed in. Login or sign up in order to post.