I'm not sure, if this is really a question or more an observation - or even a bug.
Throughout my javascript code I'm using many console.log and console.group statements to track whats happening internally. The code also does some recursion, thus making it quite important to have the indentation of the groups correct.
//working dummy code illustrating the problem var data=3; var demo=(function(){ var internal=function(){ console.group("internal"); console.log("some smart shit"); console.groupEnd(); } console.group("inside the closure1"); console.group("inside the closure2"); internal(); if (data===5){ console.log("funny Things"); } console.groupEnd(); console.log("some smart shit 1"); console.groupEnd(); }( data )); console.log("Indentation correct?!");
If all code blocks are executed, the tree built in the console goes deep, but bubbles back up to the root level of the hierarchy. Now, if a block doesn't execute an other block and nothing is logged to the console, the indentation remains at +1 after leaving the code block.
Change the
var data=5in the obove dummy code to
var data=3and you'll see that the indentation will be wrong!
More generally speaking; Nesting console.group's without using a console.log for every time console.group was called results in false indentation!
I know, that the ChromeDevTeam have referred to the firebug console api while implementing the chromedevtools and assume this behavior is the same in firebug.
I now question if anybody has experienced the same behavior? Does anybody know if this behavior is as expected? And most importantly; does anyone know a workaround to fix this indentation problem? Of course, I could console.log something every time I open up a group, but this isn't really the idea, if you ask me..
Thanks for any helpful information on this topic and sorry, if this question is kinda lame :(
//Edit Nr2 -> I've updated the code to illustrate the problem. It now generates the false indentation as described (against what I am expecting).