Skip to content

Commit

Permalink
-Enhance pass-through methods (checks, group* methods degradation wit…
Browse files Browse the repository at this point in the history
…h .log, ...)

-Join array if apply not available (IE...)
  • Loading branch information
TiTi committed Jan 9, 2011
1 parent 22984e2 commit 3f2f3cd
Showing 1 changed file with 48 additions and 33 deletions.
81 changes: 48 additions & 33 deletions ba-debug.js
@@ -1,13 +1,13 @@
/*!
* JavaScript Debug - v0.4 - 6/22/2010
* http://benalman.com/projects/javascript-debug-console-log/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* With lots of help from Paul Irish!
* http://paulirish.com/
/*!
* JavaScript Debug - v0.4 - 6/22/2010
* http://benalman.com/projects/javascript-debug-console-log/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* With lots of help from Paul Irish!
* http://paulirish.com/
*/

// Script: JavaScript Debug: A simple wrapper for console.log
Expand Down Expand Up @@ -92,7 +92,22 @@ window.debug = (function ()
// exist, as long as the logging level is non-zero.
that[method] = function ()
{
log_level !== 0 && con && con[method] && con[method].apply(con, arguments);
con = window.console; // A console might appears anytime

if(log_level !== 0 && con)
{
if(con[method] && typeof(con[method].apply) != 'undefined')
con[method].apply(con, arguments);
else
{
var args = aps.call(arguments);
if(method.indexOf('group') != -1)
{
args.unshift('['+method+']');
that['log'](args.join(' '));
}
}
}
}

})(pass_methods[idx]);
Expand Down Expand Up @@ -189,32 +204,32 @@ window.debug = (function ()

con = window.console; // A console might appears anytime

if (!is_level(idx))
return;

if (!con && !domInsertion)
{
//alert('Meh! You have no console :-( You should use debug.setDomInsertion(true); or debug.exportLogs();');
return;
}

if (!is_level(idx))
return;

if (!con && !domInsertion)
{
//alert('Meh! You have no console :-( You should use debug.setDomInsertion(true); or debug.exportLogs();');
return;
}

con[level] ? trace(level, args) : trace('log', args); // Degradation path
};

})(idx, log_methods[idx]);
}

// Call the browser console logger
function trace(level, args)
{
if (typeof (con[level].apply) != 'undefined')
{
con[level].apply(con, args); // FireFox || Firebug Lite || Opera || Chrome
}
else
{
con[level](args); // IE 8 (at least)
}
}

// Call the browser console logger
function trace(level, args)
{
if (typeof (con[level].apply) != 'undefined')
{
con[level].apply(con, args); // FireFox || Firebug Lite || Opera || Chrome
}
else
{
con[level](args.join(' ')); // IE 8 (at least)
}
}

// Execute the callback function if set.
Expand Down

0 comments on commit 3f2f3cd

Please sign in to comment.