title: AngularJS $LogProvider throws Illegal access error
body: <p>I have a mobile app that uses cordova + <a href="http://code.angularjs.org/1.2.4/angular.js" rel="nofollow">AngularJS 1.2.4</a> It works perfect on every platform I tested except some Android 2.3.X devices throw a mysterious <code>illegal access</code> exception. Below is the portion of code that raises the error. Precisely speaking, the line <code>return logFn.apply(console, args);</code> seems to be the culprit. If I remove the parameter <code>args</code> code works fine. It seems odd since variable <code>args</code> is defined at the top of the function. I don't understand what is really causing this <code>illegal access</code> error? Any one had a similar problem? Any ideas how to fix it?</p>
  
  <p>ps: Please check out inline comments to better understand the problem. There, I debugged and reported some cases.</p>
  
  <pre><code>    function consoleLog(type) {
        var console = $window.console || {},
            logFn = console[type] || console.log || noop;
        if (logFn.apply) {
          return function() {
            var args = [];
            forEach(arguments, function(arg) {
              args.push(formatError(arg));
              // console.log(typeof arg); -&gt; prints string
              // console.log(arg.toString); -&gt; prints function
              // console.log(arg); -&gt; throws illegal access error
              // console.log(arg.toString()); -&gt; throws illegal access error
            });
            // console.log(args); -&gt; throws illegal access error
            // return logFn.apply(console); -&gt; works fine w/o `args`
            return logFn.apply(console, args); -&gt; throws illegal access error
          };
        }
  
        // we are IE which either doesn't have window.console =&gt; this is noop and we do nothing,
        // or we are IE where console.log doesn't have apply so we log at least first 2 args
        return function(arg1, arg2) {
          logFn(arg1, arg2 == null ? '' : arg2);
        };
      }
  </code></pre>