2011-12-23 02:48:20 +00:00
|
|
|
/**
|
|
|
|
* Logging functions.
|
|
|
|
*
|
|
|
|
* @author ajanata
|
|
|
|
*/
|
|
|
|
|
|
|
|
cah.log = {};
|
|
|
|
|
2012-01-23 07:54:58 +00:00
|
|
|
cah.log.status = function(text, opt_class) {
|
2011-12-25 03:38:19 +00:00
|
|
|
var scroll = $("#log").prop("scrollHeight") - $("#log").height() - $("#log").prop("scrollTop") <= 5;
|
2012-01-23 07:54:58 +00:00
|
|
|
|
|
|
|
var node = $("<span></span><br/>");
|
|
|
|
$(node).text("[" + new Date().toLocaleTimeString() + "] " + text + "\n");
|
|
|
|
if (opt_class) {
|
|
|
|
$(node).addClass(opt_class);
|
|
|
|
}
|
|
|
|
$("#log").append(node);
|
|
|
|
|
2011-12-25 03:38:19 +00:00
|
|
|
if (scroll) {
|
|
|
|
$("#log").prop("scrollTop", $("#log").prop("scrollHeight"));
|
|
|
|
}
|
2011-12-23 02:48:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cah.log.error = function(text) {
|
2012-01-23 07:54:58 +00:00
|
|
|
cah.log.status("Error: " + text, "error");
|
2011-12-23 02:48:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log a message if debugging is enabled, optionally dumping the contents of an object.
|
|
|
|
*
|
|
|
|
* @param {string}
|
|
|
|
* text Text to display
|
2012-01-21 03:11:39 +00:00
|
|
|
* @param {object}
|
|
|
|
* opt_obj Optional. Object to dump along with message.
|
2011-12-23 02:48:20 +00:00
|
|
|
*/
|
|
|
|
cah.log.debug = function(text, opt_obj) {
|
2012-01-28 08:49:50 +00:00
|
|
|
if (cah.SILENT_DEBUG && console) {
|
|
|
|
console.debug("[" + new Date().toLocaleTimeString() + "]", text, opt_obj);
|
|
|
|
}
|
2011-12-23 02:48:20 +00:00
|
|
|
if (cah.DEBUG) {
|
|
|
|
if (opt_obj) {
|
|
|
|
if (JSON && JSON.stringify) {
|
|
|
|
cah.log.debug(text + ": " + JSON.stringify(opt_obj));
|
|
|
|
} else {
|
|
|
|
cah.log.debug(text + ": TODO: debug log without JSON.stringify()");
|
|
|
|
}
|
|
|
|
} else {
|
2012-01-23 07:54:58 +00:00
|
|
|
cah.log.status("DEBUG: " + text, "debug");
|
2011-12-23 02:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|