Commit 81e5adaf authored by Joel Martin's avatar Joel Martin

Refactor console logging code.

Util.Debug, Util.Info, Util.Warn, Util.Error routines instead of
direct calls to console.*. Add "logging=XXX" query variable that sets
the logging level (default is "warn").

Logging values:
    debug: code debug logging (many calls in performance path are also
           commented for performance reasons).
    info: informative messages including timing information.
    warn: significant events
    error: something has gone wrong
parent 351a1da3
...@@ -111,7 +111,7 @@ decode: function (data, offset) { ...@@ -111,7 +111,7 @@ decode: function (data, offset) {
var padding = (data.charAt(i) == pad); var padding = (data.charAt(i) == pad);
// Skip illegal characters and whitespace // Skip illegal characters and whitespace
if (c == -1) { if (c == -1) {
console.log("Illegal character '" + data.charCodeAt(i) + "'"); console.error("Illegal character '" + data.charCodeAt(i) + "'");
continue; continue;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"use strict"; "use strict";
/*jslint white: false, bitwise: false */ /*jslint white: false, bitwise: false */
/*global window, console, $, Util */ /*global window, $, Util */
var Canvas, Canvas_native; var Canvas, Canvas_native;
...@@ -49,7 +49,7 @@ onMouseButton: function(e, down) { ...@@ -49,7 +49,7 @@ onMouseButton: function(e, down) {
evt = (e ? e : window.event); evt = (e ? e : window.event);
pos = Util.getEventPosition(e, $(Canvas.id)); pos = Util.getEventPosition(e, $(Canvas.id));
bmask = 1 << evt.button; bmask = 1 << evt.button;
//console.log('mouse ' + pos.x + "," + pos.y + " down: " + down + " bmask: " + bmask); //Util.Debug('mouse ' + pos.x + "," + pos.y + " down: " + down + " bmask: " + bmask);
if (Canvas.mouseButton) { if (Canvas.mouseButton) {
Canvas.mouseButton(pos.x, pos.y, down, bmask); Canvas.mouseButton(pos.x, pos.y, down, bmask);
} }
...@@ -75,7 +75,7 @@ onMouseWheel: function (e) { ...@@ -75,7 +75,7 @@ onMouseWheel: function (e) {
} else { } else {
bmask = 1 << 4; bmask = 1 << 4;
} }
//console.log('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y); //Util.Debug('mouse scroll by ' + wheelData + ':' + pos.x + "," + pos.y);
if (Canvas.mouseButton) { if (Canvas.mouseButton) {
Canvas.mouseButton(pos.x, pos.y, 1, bmask); Canvas.mouseButton(pos.x, pos.y, 1, bmask);
Canvas.mouseButton(pos.x, pos.y, 0, bmask); Canvas.mouseButton(pos.x, pos.y, 0, bmask);
...@@ -89,14 +89,14 @@ onMouseMove: function (e) { ...@@ -89,14 +89,14 @@ onMouseMove: function (e) {
var evt, pos; var evt, pos;
evt = (e ? e : window.event); evt = (e ? e : window.event);
pos = Util.getEventPosition(e, $(Canvas.id)); pos = Util.getEventPosition(e, $(Canvas.id));
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y); //Util.Debug('mouse ' + evt.which + '/' + evt.button + ' up:' + pos.x + "," + pos.y);
if (Canvas.mouseMove) { if (Canvas.mouseMove) {
Canvas.mouseMove(pos.x, pos.y); Canvas.mouseMove(pos.x, pos.y);
} }
}, },
onKeyDown: function (e) { onKeyDown: function (e) {
//console.log("keydown: " + Canvas.getKeysym(e)); //Util.Debug("keydown: " + Canvas.getKeysym(e));
if (! Canvas.focused) { if (! Canvas.focused) {
return true; return true;
} }
...@@ -108,7 +108,7 @@ onKeyDown: function (e) { ...@@ -108,7 +108,7 @@ onKeyDown: function (e) {
}, },
onKeyUp : function (e) { onKeyUp : function (e) {
//console.log("keyup: " + Canvas.getKeysym(e)); //Util.Debug("keyup: " + Canvas.getKeysym(e));
if (! Canvas.focused) { if (! Canvas.focused) {
return true; return true;
} }
...@@ -128,27 +128,27 @@ onMouseDisable: function (e) { ...@@ -128,27 +128,27 @@ onMouseDisable: function (e) {
(evt.clientY >= pos.y) && (evt.clientY >= pos.y) &&
(evt.clientX < (pos.x + Canvas.c_wx)) && (evt.clientX < (pos.x + Canvas.c_wx)) &&
(evt.clientY < (pos.y + Canvas.c_wy))) { (evt.clientY < (pos.y + Canvas.c_wy))) {
//console.log("mouse event disabled"); //Util.Debug("mouse event disabled");
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
} }
//console.log("mouse event not disabled"); //Util.Debug("mouse event not disabled");
return true; return true;
}, },
init: function (id) { init: function (id) {
var c, imgTest, arora; var c, imgTest, arora;
console.log(">> Canvas.init"); Util.Debug(">> Canvas.init");
Canvas.id = id; Canvas.id = id;
c = $(Canvas.id); c = $(Canvas.id);
if (Canvas_native) { if (Canvas_native) {
console.log("Using native canvas"); Util.Info("Using native canvas");
// Use default Canvas functions // Use default Canvas functions
} else { } else {
console.warn("Using excanvas canvas emulation"); Util.Warn("Using excanvas canvas emulation");
//G_vmlCanvasManager.init(c); //G_vmlCanvasManager.init(c);
//G_vmlCanvasManager.initElement(c); //G_vmlCanvasManager.initElement(c);
} }
...@@ -176,22 +176,22 @@ init: function (id) { ...@@ -176,22 +176,22 @@ init: function (id) {
} catch (exc) {} } catch (exc) {}
if (Canvas.has_imageData) { if (Canvas.has_imageData) {
console.log("Canvas supports imageData"); Util.Info("Canvas supports imageData");
Canvas.force_canvas = false; Canvas.force_canvas = false;
if (Canvas.ctx.createImageData) { if (Canvas.ctx.createImageData) {
// If it's there, it's faster // If it's there, it's faster
console.log("Using Canvas createImageData"); Util.Info("Using Canvas createImageData");
Canvas._imageData = Canvas._imageDataCreate; Canvas._imageData = Canvas._imageDataCreate;
} else if (Canvas.ctx.getImageData) { } else if (Canvas.ctx.getImageData) {
console.log("Using Canvas getImageData"); Util.Info("Using Canvas getImageData");
Canvas._imageData = Canvas._imageDataGet; Canvas._imageData = Canvas._imageDataGet;
} }
console.log("Prefering javascript operations"); Util.Info("Prefering javascript operations");
Canvas.prefer_js = true; Canvas.prefer_js = true;
Canvas._rgbxImage = Canvas._rgbxImageData; Canvas._rgbxImage = Canvas._rgbxImageData;
Canvas._cmapImage = Canvas._cmapImageData; Canvas._cmapImage = Canvas._cmapImageData;
} else { } else {
console.log("Canvas lacks imageData, using fillRect (slow)"); Util.Warn("Canvas lacks imageData, using fillRect (slow)");
Canvas.force_canvas = true; Canvas.force_canvas = true;
Canvas.prefer_js = false; Canvas.prefer_js = false;
Canvas._rgbxImage = Canvas._rgbxImageFill; Canvas._rgbxImage = Canvas._rgbxImageFill;
...@@ -202,14 +202,14 @@ init: function (id) { ...@@ -202,14 +202,14 @@ init: function (id) {
Canvas.prevStyle = ""; Canvas.prevStyle = "";
Canvas.focused = true; Canvas.focused = true;
//console.log("<< Canvas.init"); Util.Debug("<< Canvas.init");
return true; return true;
}, },
start: function (keyPress, mouseButton, mouseMove) { start: function (keyPress, mouseButton, mouseMove) {
var c; var c;
console.log(">> Canvas.start"); Util.Debug(">> Canvas.start");
c = $(Canvas.id); c = $(Canvas.id);
Canvas.keyPress = keyPress || null; Canvas.keyPress = keyPress || null;
...@@ -228,7 +228,7 @@ start: function (keyPress, mouseButton, mouseMove) { ...@@ -228,7 +228,7 @@ start: function (keyPress, mouseButton, mouseMove) {
Util.addEvent(document, 'click', Canvas.onMouseDisable); Util.addEvent(document, 'click', Canvas.onMouseDisable);
Util.addEvent(document.body, 'contextmenu', Canvas.onMouseDisable); Util.addEvent(document.body, 'contextmenu', Canvas.onMouseDisable);
//console.log("<< Canvas.start"); Util.Debug("<< Canvas.start");
}, },
clear: function () { clear: function () {
...@@ -390,7 +390,6 @@ _cmapImageData: function(x, y, width, height, arr, offset) { ...@@ -390,7 +390,6 @@ _cmapImageData: function(x, y, width, height, arr, offset) {
_cmapImageFill: function(x, y, width, height, arr, offset) { _cmapImageFill: function(x, y, width, height, arr, offset) {
var sx = 0, sy = 0; var sx = 0, sy = 0;
cmap = Canvas.colourMap; cmap = Canvas.colourMap;
console.log("here1: arr[2]: " + arr[2] + ", cmap[arr[2]]: " + cmap[arr[2]]);
for (i=0, j=offset; i < (width * height); i+=1, j+=1) { for (i=0, j=offset; i < (width * height); i+=1, j+=1) {
Canvas.fillRect(x+sx, y+sy, 1, 1, [arr[j]]); Canvas.fillRect(x+sx, y+sy, 1, 1, [arr[j]]);
sx += 1; sx += 1;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* See README.md for usage and integration instructions. * See README.md for usage and integration instructions.
*/ */
"use strict"; "use strict";
/*global console, $, RFB, Canvas, VNC_uri_prefix, Element, Fx */ /*global $, RFB, Canvas, VNC_uri_prefix, Element, Fx */
// Load mootools // Load mootools
(function () { (function () {
...@@ -168,16 +168,16 @@ clipClear: function() { ...@@ -168,16 +168,16 @@ clipClear: function() {
}, },
clipReceive: function(text) { clipReceive: function(text) {
console.log(">> DefaultControls.clipReceive: " + text.substr(0,40) + "..."); Util.Debug(">> DefaultControls.clipReceive: " + text.substr(0,40) + "...");
$('VNC_clipboard_text').value = text; $('VNC_clipboard_text').value = text;
console.log("<< DefaultControls.clipReceive"); Util.Debug("<< DefaultControls.clipReceive");
}, },
clipSend: function() { clipSend: function() {
var text = $('VNC_clipboard_text').value; var text = $('VNC_clipboard_text').value;
console.log(">> DefaultControls.clipSend: " + text.substr(0,40) + "..."); Util.Debug(">> DefaultControls.clipSend: " + text.substr(0,40) + "...");
RFB.clipboardPasteFrom(text); RFB.clipboardPasteFrom(text);
console.log("<< DefaultControls.clipSend"); Util.Debug("<< DefaultControls.clipSend");
} }
}; };
...@@ -13,28 +13,37 @@ ...@@ -13,28 +13,37 @@
// Globals defined here // Globals defined here
var Util = {}, $; var Util = {}, $;
// Debug routines
// Logging/debug routines
if (typeof window.console === "undefined") { if (typeof window.console === "undefined") {
if (typeof window.opera !== "undefined") {
window.console = { window.console = {
'log': function(m) {}, 'log' : window.opera.postError,
'warn': function(m) {}, 'warn' : window.opera.postError,
'error': window.opera.postError };
} else {
window.console = {
'log' : function(m) {},
'warn' : function(m) {},
'error': function(m) {}}; 'error': function(m) {}};
}
if (/__debug__$/i.test(document.location.href)) {
if (typeof window.opera !== "undefined") {
window.console.log = window.opera.postError;
window.console.warn = window.opera.postError;
window.console.error = window.opera.postError;
} }
} else {
/*
// non-debug mode, an empty function
window.console.log = function (message) {};
window.console.warn = function (message) {};
window.console.error = function (message) {};
*/
} }
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
Util.logging = (document.location.href.match(
/logging=([A-Za-z0-9\._\-]*)/) || ['', 'warn'])[1];
switch (Util.logging) {
case 'debug': Util.Debug = function (msg) { console.log(msg); };
case 'info': Util.Info = function (msg) { console.log(msg); };
case 'warn': Util.Warn = function (msg) { console.warn(msg); };
case 'error': Util.Error = function (msg) { console.error(msg); };
break;
default:
throw("invalid logging type '" + Util.logging + "'");
}
// Simple DOM selector by ID // Simple DOM selector by ID
if (!window.$) { if (!window.$) {
$ = function (id) { $ = function (id) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment