title: Adding depth parameter to console.log for recursion
body: <p>I'm trying to debug a recursive function, and it would be nice if I could keep track of the depth.  I attempted to write a version of console.log that took a depth parameter and prepended a corresponding number of spaces to the log, but it doesn't quite work right.  The biggest problem is that jquery objects are displayed differently when run through the Chrome debugger.  Ideally the dlog function would be identical to console.log except for prepending n spaces, where n = depth * 2.</p>
  
  <pre><code>&lt;!-- nested divs --&gt;
  &lt;style&gt;
    .node {margin-left:20px}
  &lt;/style&gt;
  
  &lt;div class = 'container'&gt;
    &lt;div class='node'&gt;&lt;span class='text'&gt;1&lt;/span&gt;
      &lt;div class='node'&gt;&lt;span class='text'&gt;2&lt;/span&gt;
        &lt;div class='node'&gt;&lt;span class='text'&gt;3&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'&gt;&lt;/script&gt;
  &lt;script&gt;
  
  // Log with depth
  function dlog() {
    var depth = arguments[arguments.length - 1]
    var real_args = []
    for(var i = 0; i &lt; arguments.length - 1; i++)
      real_args.push(arguments[i])
    var ds = ''
    for(var i = 0; i &lt; depth; i++) ds += '  '
    console.log(ds, real_args)
  }
  
  // Just walk through the node tree, logging as we go.
  function walk_node(node, depth) {
    dlog('walking node: ', node, depth)
    console.log('walking node: ', node)
    var child = node.children('.node').first()
    if(child.length &gt; 0)  walk_node(child, depth + 1)
  }
  
  walk_node($('.container'), 0)
  &lt;/script&gt;
  </code></pre>