From 3f2f3cd342621213cf3b19ff41d28d3ef826b373 Mon Sep 17 00:00:00 2001 From: TiTi Date: Sun, 9 Jan 2011 23:18:54 +0100 Subject: [PATCH] -Enhance pass-through methods (checks, group* methods degradation with .log, ...) -Join array if apply not available (IE...) --- ba-debug.js | 81 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/ba-debug.js b/ba-debug.js index 90bfd34..f205c69 100644 --- a/ba-debug.js +++ b/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 @@ -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.