From 33fa91fccdf81bcaa0ad42e897d7d6d95c44985f Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 9 Nov 2016 22:29:16 +0800 Subject: webui: Append server-pushed logging messages to the logging box * Colorize the logging messages of different level with different colors * Also add a different icon for each message --- fg21sim/webui/static/js/console.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'fg21sim/webui/static/js/console.js') diff --git a/fg21sim/webui/static/js/console.js b/fg21sim/webui/static/js/console.js index 6d5783a..f9e75dc 100644 --- a/fg21sim/webui/static/js/console.js +++ b/fg21sim/webui/static/js/console.js @@ -57,6 +57,30 @@ var updateTaskStatus = function (status) { }; +/** + * Append the logging messages to the "#log-messages" panel box + * + * @param {Object} msg - Server pushed logging message of "action=log" + */ +var appendLogMessage = function (msg) { + var log_icons = { + debug: "", + info: "", + warning: "", + error: "", + critical: "", + }; + var level = msg.levelname.toLowerCase(); + var ele = $("

").addClass("code log log-" + level); + ele.append($(log_icons[level])); + ele.append($("").addClass("asctime").text(msg.asctime)); + ele.append($("").addClass("levelname").text(msg.levelname)); + ele.append($("").addClass("name").text(msg.name)); + ele.append($("").addClass("message").text(msg.message)); + ele.appendTo("#log-messages"); +}; + + /** * Get the task status from the server * @@ -84,7 +108,7 @@ var startServerTask = function (ws, time) { */ var handleMsgConsole = function (msg) { if (msg.action === "log") { - // TODO: show the logging messages + appendLogMessage(msg); } else if (msg.action === "push") { // Update the task status -- cgit v1.2.2