Literówka - zamiast self powinno byæ this.
[redakcja.git] / project / static / js / jquery.logging.js
index 1afd8be..d6cee14 100644 (file)
@@ -1,35 +1,41 @@
 (function($) {
-       const LEVEL_DEBUG = 1;
-       const LEVEL_INFO = 2;
-       const LEVEL_WARN = 3;
-
-       const LOG_LEVEL = LEVEL_DEBUG;
-
-       var mozillaLog = function(msg) {
-               if (window.console) console.log(msg);
+       var LEVEL_DEBUG = 1;
+       var LEVEL_INFO = 2;
+       var LEVEL_WARN = 3;
+       var LOG_LEVEL = LEVEL_DEBUG;
+       
+        var standardLog = function() {
+            if (window.console)
+                console.log.apply(console, arguments);
+        };
+    
+       var operaLog = function() {
+               opera.postError(arguments.join(' '));
        };
 
-       var operaLog = function(msg) {
-               opera.postError(msg);
+        var msieLog = function() {
+            var args = $.makeArray(arguments);
+            var vals = $.map(args, function(n) {
+                try {
+                    return JSON.stringify(n);
+                } catch(e) {
+                    return ('' + n);
+                }
+            });
+
+            if (window.console)
+                console.log(vals.join(" "));
+        };
+
+       $.log = function() {
+               return $.log.browserLog.apply(this, arguments);
        };
 
-       var defaultLog = function(msg) { return false; };
-
-       $.log = function(message, level) {
-               if (level == null) level = LEVEL_INFO;
-               if (message == null) message = 'TRACE';
-               if (level < LOG_LEVEL)
-                       return false;
-
-               return $.log.browserLog(message);
-       };
-
-       if ($.browser.mozilla || $.browser.safari)
-               $.log.browserLog = mozillaLog;
-       else if($.browser.opera)
-               $.log.browserLog = operaLog
-       else 
-               $.log.browserLog = defaultLog;
-
+        if($.browser.opera)
+            $.log.browserLog = operaLog;
+        else if($.browser.msie)
+            $.log.browserLog = msieLog;
+        else
+            $.log.browserLog = standardLog;
 
 })(jQuery);