Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronous console logging in Chrome

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.

like image 796
Mikulas Dite Avatar asked Apr 06 '12 08:04

Mikulas Dite


People also ask

Is console log synchronous or asynchronous?

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.

Does console log affect performance?

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.

Is Nodejs console log async?

Console. log is asynchronous in windows while it is synchronous in linux/mac.


3 Answers

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

like image 172
Fox32 Avatar answered Oct 18 '22 14:10

Fox32


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"}

like image 24
kulpae Avatar answered Oct 18 '22 14:10

kulpae


Put a breakpoint(see image below) at console.log statement and use controls to step over to next.

enter image description here

like image 2
Sandeep Manne Avatar answered Oct 18 '22 14:10

Sandeep Manne