Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
Save Console.log output to variable

This question is similar in nature to Converting an object to a string

console.log works awfully good. It can log very deep objects, self-referencing objects, nulls, undefined, multiparams...

How can I store the output of the function as a string? I want to have my own logging system, but I want to keep the same format as console.log.

The most voted answer for the referenced question does not work with self referencing objects. Nor does .toString():

> a = {}
{}
> a.b = a
<ref *1> { b: [Circular *1] }
> a
<ref *1> { b: [Circular *1] }
> a.b
<ref *1> { b: [Circular *1] }
> JSON.stringify(a)
Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    --- property 'b' closes the circle
    at JSON.stringify (<anonymous>)
> console.log(a)
<ref *1> { b: [Circular *1] }
undefined
> a.toString()
'[object Object]'

Basically I would want some function stringify with

> stringify(a) === '<ref *1> { b: [Circular *1] }'

The question is also similar to How can I print a circular structure in a JSON-like format? but not exactly. The question there is to log one self referencing object. I'm asking for something more generic, which is something like the console output. In particular, console handles gracefully multiparams

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda