Is it posible to make logging to the console synchronous? I often run into situations where the code execution is faster than dumping the structures. That resolves in outputting already changed objects.
I sure can walk through the code with debugger, make unit tests etc., it's just often convenient to simply console.log
stuff just to make a general idea of what is going on.
console. log() is put in the event queue until all code is executed, then it is ran and it would have the bar property. It appears though it is running synchronously.
We already know that logging is affecting performance, especially when we use console. log because its a syncronous process. In nodejs, we have to use asyncronous process to get the best performance.
Console. log is asynchronous in windows while it is synchronous in linux/mac.
You could create a copy of the object before passing it to console.log
. Look here for a function to create a deep copy of your object.
Edit:
Now implemented in Chrome, see here
I just got caught by this behaviour, spent some hours until I realized the console is borked, not my code. damn.
Until now I only managed to get expected behaviour with:
console.log(JSON.stringify(obj))
nice side effect is, it expands the objects like {0: "a", 3: "b"}
Put a breakpoint(see image below) at console.log statement and use controls to step over to next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With