Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
Is there a function that allows you to listen for console logs in javascript?

I've tried searching it up with multiple different wordings and on multiple websites with no answer, is it possible, is it not, and if so, how? I need to be able to get code to run when anythign is logged to the console and get what that thing was.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can override console.log's default behavior:

var log = console.log;

var logs = []
console.log = function(e) {
  log.apply(console, [].slice.call(arguments));
  logs.push(e) //custom code
};

console.log("Hello World!")

console.log('Printed logs:', logs)

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. Save the original console

    var log = console.log;

  2. Monkey patch it i.e. modify it when run and all at runtime //use the log instance and 'apply()' method to apply to inherit it //we pass in a date for each call of console.log() when using the original ( log() )

    log.apply(console, [(new Date().toString())].concat([].slice.call(arguments)) ); };

  3. Now everytime we call - log() - we are calling the original //to test it do this

    log('test','this is the original console.log());

  4. This is the patched version

    console.log("This is the Monkey Patched console.log()!", "More text...");

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda