From c1eba48f79b0131bec7cb8d4a95fafaa088956e7 Mon Sep 17 00:00:00 2001
From: Joel Martin <github@martintribe.org>
Date: Wed, 22 Sep 2010 17:11:57 -0500
Subject: [PATCH] logging: add Util.get_logging(), canvas clearing.

Only clear canvas if log level is not debug instead of using
'#__debug__' in the URL.
---
 include/rfb.js  |  2 +-
 include/util.js | 16 +++++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/include/rfb.js b/include/rfb.js
index 2fc7655..365c513 100644
--- a/include/rfb.js
+++ b/include/rfb.js
@@ -366,7 +366,7 @@ updateState = function(state, statusMsg) {
 
         if (canvas && canvas.getContext()) {
             canvas.stop();
-            if (! /__debug__$/i.test(document.location.href)) {
+            if (Util.get_logging() !== 'debug') {
                 canvas.clear();
             }
         }
diff --git a/include/util.js b/include/util.js
index 7077397..272da9a 100644
--- a/include/util.js
+++ b/include/util.js
@@ -59,7 +59,16 @@ Array.prototype.push32 = function (num) {
  * Logging/debug routines
  */
 
+Util._log_level = 'warn';
 Util.init_logging = function (level) {
+    if (typeof level === 'undefined') {
+        Util._log_level = (document.location.href.match(
+                /logging=([A-Za-z0-9\._\-]*)/) ||
+                ['', Util._log_level])[1];
+        level = Util._log_level;
+    } else {
+        Util._log_level = level;
+    }
     if (typeof window.console === "undefined") {
         if (typeof window.opera !== "undefined") {
             window.console = {
@@ -86,10 +95,11 @@ Util.init_logging = function (level) {
             throw("invalid logging type '" + level + "'");
     }
 };
+Util.get_logging = function () {
+        return Util._log_level;
+    }
 // Initialize logging level
-Util.init_logging( (document.location.href.match(
-                    /logging=([A-Za-z0-9\._\-]*)/) ||
-                    ['', 'warn'])[1] );
+Util.init_logging();
 
 Util.dirObj = function (obj, depth, parent) {
     var i, msg = "", val = "";
-- 
2.18.1