diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-09 22:29:16 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-09 22:29:16 +0800 |
commit | 33fa91fccdf81bcaa0ad42e897d7d6d95c44985f (patch) | |
tree | ffade76d73071769741b032fe9e85156809231ef /fg21sim/webui/static/js | |
parent | aef666a6e1e1b2501f9779914627062a146dd21e (diff) | |
download | fg21sim-33fa91fccdf81bcaa0ad42e897d7d6d95c44985f.tar.bz2 |
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
Diffstat (limited to 'fg21sim/webui/static/js')
-rw-r--r-- | fg21sim/webui/static/js/console.js | 26 |
1 files changed, 25 insertions, 1 deletions
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 @@ -58,6 +58,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: "<span class='icon fa fa-comment'></span>", + info: "<span class='icon fa fa-info-circle'></span>", + warning: "<span class='icon fa fa-warning'></span>", + error: "<span class='icon fa fa-times-circle'></span>", + critical: "<span class='icon fa fa-times-circle'></span>", + }; + var level = msg.levelname.toLowerCase(); + var ele = $("<p>").addClass("code log log-" + level); + ele.append($(log_icons[level])); + ele.append($("<span>").addClass("asctime").text(msg.asctime)); + ele.append($("<span>").addClass("levelname").text(msg.levelname)); + ele.append($("<span>").addClass("name").text(msg.name)); + ele.append($("<span>").addClass("message").text(msg.message)); + ele.appendTo("#log-messages"); +}; + + +/** * Get the task status from the server * * @param {Object} ws - The opened WebSocket object through which to send @@ -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 |