1

Say I have a function imported from a library

import doSomething from 'someLibrary';

And doSomething has a console.log() call inside of it. So, when I call do something

doSomething();

Some message is logged to the console. How do I call the function doSomething without it logging anything to the console?

4
  • 1
    Not something you can easily do. You can overwrite the global console.log with your own custom function that swallows input, but that will nullify any logging from happening including your own. Commented Aug 18, 2021 at 18:53
  • 3
    If someLibrary is open-source on GitHub or similar, reach out to the developer and let them know that is happening. Since someLibrary is likely to be in node_modules (or similar), it is considered "Vendor Code" and shouldn't be modified directly. Alternatively, make your own "fork" and patch the issue yourself. Commented Aug 18, 2021 at 18:55
  • It is the firebase admin-sdk, admin.auth().updateUser. If the user email is updated, it logs a link for the user to reset their email to the previous one. I only see this log, however, when called in my tests using the emulator, and not when called on the actual site. Commented Aug 18, 2021 at 19:05
  • I was mainly wondering if this is possible to do elegantly, but I guess not. Commented Aug 18, 2021 at 19:10

1 Answer 1

0

Try this:

{
    let console = {log: ()=>{}};
    doSomething();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Explain what it does and why it would help OP ;)
And also the drawbacks of doing this..
It overwrite console object in local scope, in function doSomething It calls empty function log. Problem may occure if doSomething try to get other console property.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.