Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Intercepting a console.log created by a node_module to display in a toast

I am trying to use a console.log() created from within a node_module to display a toast on screen for the user.

I have my toasts working. I'm just not sure how to capture the log message since it is not being created from my personal code. Is this possible?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

WARNING: This is extremely bad practice. It is not recommended to change the behavior of a native function especially not console.log.

That being said you can technically intercept logs by redefining the log function and then using console.info to still log things.

console.log = function(...args) {
   alert("logged")
   console.info(...args);
}

I recommend forking the NPM package instead and implementing your own logic.

about 4 years ago · Juan Pablo Isaza Report

0

Override the global console's log method with a method named log that you define:

var previous = console.log;
console.log = function() {
    // Do whatever you need here:
    // call your own function with the original arguments
    yourFunction.apply(thisObj, arguments);
 
    // do the normal console.log if you want
    previous.apply(thisObj, arguments);
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!