diff --git a/include/rfb.js b/include/rfb.js
index 2fc765507d637ed7694a54758f25e8847184d561..365c513c982963d93407c7ece1c59d199d0c6a31 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 707739777259dcb94f6edefaf7e892d42d44003f..272da9aa68e620eb34c961750acb538246cff2b6 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 = "";