From 1c74d2e50bf888db6b6686b0a6ddb7d36cad40de Mon Sep 17 00:00:00 2001 From: Martin Muehlhaeuser Date: Tue, 23 Jan 2018 18:30:55 +0000 Subject: [PATCH] logging: Serverside timestamping of messages --- octoprint_klipper/__init__.py | 16 ++++++++++++++-- octoprint_klipper/static/js/klipper.js | 16 ++++------------ octoprint_klipper/templates/klipper_tab.jinja2 | 5 +++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/octoprint_klipper/__init__.py b/octoprint_klipper/__init__.py index 06ec459..064ab47 100644 --- a/octoprint_klipper/__init__.py +++ b/octoprint_klipper/__init__.py @@ -1,5 +1,6 @@ # coding=utf-8 from __future__ import absolute_import +import datetime import logging import octoprint.plugin import octoprint.plugin.core @@ -42,10 +43,21 @@ class KlipperPlugin( message = "" def logInfo(self, message): - self._plugin_manager.send_plugin_message(self._identifier, dict(type="info", message=message)) + self._plugin_manager.send_plugin_message( + self._identifier, + dict( + time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + type="info", message=message) + ) def logError(self, error): - self._plugin_manager.send_plugin_message(self._identifier, dict(type="error", message=error)) + self._plugin_manager.send_plugin_message( + self._identifier, + dict( + time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), + type="error", + message=error) + ) def on_parse_gcode(self, comm, line, *args, **kwargs): if "//" in line: diff --git a/octoprint_klipper/static/js/klipper.js b/octoprint_klipper/static/js/klipper.js index 6ce7e81..fd5ec4d 100644 --- a/octoprint_klipper/static/js/klipper.js +++ b/octoprint_klipper/static/js/klipper.js @@ -11,15 +11,7 @@ $(function() { self.shortStatus = ko.observable(); self.logMessages = ko.observableArray(); - /* - self.onConnectToHost = function() { - console.log("Connecting"); - self.shortStatus("Connecting to Host"); - OctoPrint.connection.connect({"port" : "VIRTUAL"}); - self.connectButtonText("Disconnect"); - console.log(self.loginState); - }*/ - + self.onGetStatus = function() { self.shortStatus("Update Status") OctoPrint.control.sendGcode("Status") @@ -49,11 +41,11 @@ $(function() { self.onDataUpdaterPluginMessage = function(plugin, message) { //console.log(message); - self.logMessage(message["message"]); + self.logMessage(message["time"], message["type"], message["message"]); } - self.logMessage = function(message) { - self.logMessages.push({time: Date.now(), msg: message}); + self.logMessage = function(timestamp, type, message) { + self.logMessages.push({time: timestamp, type: type, msg: message}); } self.onClearLog = function() { diff --git a/octoprint_klipper/templates/klipper_tab.jinja2 b/octoprint_klipper/templates/klipper_tab.jinja2 index 031ca99..34368b6 100644 --- a/octoprint_klipper/templates/klipper_tab.jinja2 +++ b/octoprint_klipper/templates/klipper_tab.jinja2 @@ -3,7 +3,7 @@
-
+
@@ -13,7 +13,8 @@ - + +