Permalink
Browse files

-Enhance pass-through methods (checks, group* methods degradation wit…

…h .log, ...)

-Join array if apply not available (IE...)
  • Loading branch information...
TiTi committed Jan 9, 2011
1 parent 22984e2 commit 3f2f3cd342621213cf3b19ff41d28d3ef826b373
Showing with 48 additions and 33 deletions.
  1. +48 −33 ba-debug.js
View
@@ -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
@@ -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]);
@@ -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.

0 comments on commit 3f2f3cd

Please sign in to comment.