Changed zouba directory heirarchy.
[ptas] / zouba / wrt / WRTKit / Utils / Logger.js
diff --git a/zouba/wrt/WRTKit/Utils/Logger.js b/zouba/wrt/WRTKit/Utils/Logger.js
new file mode 100644 (file)
index 0000000..efbdfdc
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+� Copyright 2008 Nokia Corporation. All rights reserved.\r
+\r
+IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia\r
+Corporation (�Nokia�) in consideration of your agreement to the following terms. Your use, installation\r
+and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If\r
+you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example\r
+Widget files.\r
+\r
+In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia\r
+grants you a personal, non-exclusive license, under Nokia�s copyrights in the WRTKit and Example\r
+Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,\r
+CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60\r
+Widgets.\r
+\r
+If you redistribute the WRTKit and Example files, you must retain this entire notice in all such\r
+redistributions of the WRTKit and Example files.\r
+\r
+You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products\r
+that include the WRTKit and Example files without the prior written explicit agreement with Nokia.\r
+Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by\r
+Nokia herein, including but not limited to any patent rights that may be infringed by your products that\r
+incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files\r
+may be incorporated.\r
+\r
+The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO\r
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED\r
+WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A\r
+PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION\r
+ALONE OR IN COMBINATION WITH YOUR PRODUCTS.\r
+\r
+IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR\r
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR\r
+DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY\r
+OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,\r
+EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+*/\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// Logger utility class that uses the Firebug console class.\r
+\r
+// Constructor (everything is static so this is empty).\r
+function Logger() {\r
+    // Set default logger level.\r
+    this.level = this.LOG_LEVEL_OFF;\r
+}\r
+\r
+// Logger levels.\r
+Logger.prototype.LOG_LEVEL_DEBUG = 0;\r
+Logger.prototype.LOG_LEVEL_INFO = 1;\r
+Logger.prototype.LOG_LEVEL_WARN = 2;\r
+Logger.prototype.LOG_LEVEL_ERROR = 3;\r
+Logger.prototype.LOG_LEVEL_OFF = 4;\r
+\r
+Logger.prototype.level = null;\r
+Logger.prototype.filter = null;\r
+\r
+// Disable logging on other browsers except Firefox.\r
+Logger.prototype.enabled = (navigator.userAgent.indexOf("Firefox") != -1);\r
+\r
+// Dumps an objects properties and methods to the console.\r
+Logger.prototype.dump = function(obj) {\r
+    if (this.enabled) {\r
+        console.dir(obj);\r
+    }\r
+}\r
+\r
+// Dumps a stracktrace to the console.\r
+Logger.prototype.trace = function() {\r
+    if (this.enabled) {\r
+        console.trace();\r
+    }\r
+}\r
+\r
+// Prints a debug message to the console.\r
+Logger.prototype.debug = function(str) {\r
+    if (this.enabled && this.level <= this.LOG_LEVEL_DEBUG) {\r
+        if (this.filter == null) {\r
+            console.debug(str);\r
+        } else {\r
+            var show = false;\r
+            for (i in this.filter) {\r
+                if (str.indexOf(this.filter[i]) >= 0) {\r
+                    show = true;\r
+                    break;\r
+                }\r
+            }\r
+            if (show) {\r
+                console.debug(str);\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+// Prints an info message to the console.\r
+Logger.prototype.info = function(str) {\r
+    if (this.enabled && this.level <= this.LOG_LEVEL_INFO) {\r
+        console.info(str);\r
+    }\r
+}\r
+\r
+// Prints a warning message to the console.\r
+Logger.prototype.warn = function(str) {\r
+    if (this.enabled && this.level <= this.LOG_LEVEL_WARN) {\r
+        console.warn(str);\r
+    }\r
+}\r
+\r
+// Prints an error message to the console.\r
+Logger.prototype.error = function(str) {\r
+    if (this.enabled && this.level <= this.LOG_LEVEL_ERROR) {\r
+        console.error(str);\r
+    }\r
+}\r