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

257
Visualizações
javascript custom console log function keeping stack trace

I have a helper function that prepends some message when calling console.log:

function log(...arg: any[]): void {
  const LOG_PREFIX = `[file.ts]`;
  // 1. Convert args to a normal array
  const args: any[] = Array.prototype.slice.call(arguments);
  // 2. Prepend log prefix log string
  args.unshift(LOG_PREFIX);
  // 3. Pass along arguments to console.log
  console.log.call(console, ...args);
}

The problem is that when it logs, the console shows a clickable link to this log:8 or the line that calls console.log.call(console, ...args)

Is there a way I can adjust this method so that it keeps the intended stack trace of where i call this method instead?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

There you go, Function.prototype.bind() is to the rescue:

const log = console.log.bind(window.console, "[file.ts]");

log("test", "blah");
console.log("test", "blah");

about 4 years ago · Santiago Gelvez 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