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/css/main.css | 28 ++++++++++++++++++++++++++++ fg21sim/webui/static/js/console.js | 26 +++++++++++++++++++++++++- fg21sim/webui/templates/console.html | 12 +++++++++--- 3 files changed, 62 insertions(+), 4 deletions(-) (limited to 'fg21sim/webui') diff --git a/fg21sim/webui/static/css/main.css b/fg21sim/webui/static/css/main.css index a574990..de40123 100644 --- a/fg21sim/webui/static/css/main.css +++ b/fg21sim/webui/static/css/main.css @@ -374,11 +374,39 @@ button, font-size: 1.6rem; font-weight: bold; } +.panel-control { + float: right; +} .panel-body { padding: 1.5rem; } +/** + * Logging messages styles + */ +p.log { + font-size: 1.3rem; + margin-bottom: 0; +} +p.log span { + margin-right: 0.8rem; +} +p.log.log-debug { + color: inherit; +} +p.log.log-info { + color: #398439; +} +p.log.log-warning { + color: #d58512; +} +p.log.log-error, +p.log.log-critical { + color: #ac2925; +} + + /** * Horizontal rules */ 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 diff --git a/fg21sim/webui/templates/console.html b/fg21sim/webui/templates/console.html index e7853c9..ca082cc 100644 --- a/fg21sim/webui/templates/console.html +++ b/fg21sim/webui/templates/console.html @@ -22,12 +22,18 @@

-
+
Logging Messages + + + + + + +
-
-

messages ...

+
-- cgit v1.2.2