From 932ede865b9fe8ed86b9a3346e03cb52c75beddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 19 Sep 2019 21:47:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20connection.log=20toggling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/__init__.py | 25 +- src/octoprint/comm/protocol/__init__.py | 4 +- src/octoprint/printer/standard.py | 11 +- src/octoprint/server/api/settings.py | 28 ++ src/octoprint/server/views.py | 6 +- src/octoprint/settings.py | 8 +- .../static/js/app/viewmodels/settings.js | 3 + .../dialogs/settings/connection.jinja2 | 59 +++ .../settings/connectionprofiles.jinja2 | 30 -- .../dialogs/settings/serialconnection.jinja2 | 435 ------------------ 10 files changed, 112 insertions(+), 497 deletions(-) create mode 100644 src/octoprint/templates/dialogs/settings/connection.jinja2 delete mode 100644 src/octoprint/templates/dialogs/settings/connectionprofiles.jinja2 delete mode 100644 src/octoprint/templates/dialogs/settings/serialconnection.jinja2 diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index a8f4c2d81..dc05299d9 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -256,20 +256,12 @@ def init_logging(settings, use_logging_file=True, logging_file=None, default_con "backupCount": 6, "filename": os.path.join(settings.getBaseFolder("logs"), "octoprint.log") }, - "protocolFile": { + "connectionFile": { "class": "octoprint.logging.handlers.CommunicationLogHandler", "level": "DEBUG", "formatter": "communication", "backupCount": 3, - "filename": os.path.join(settings.getBaseFolder("logs"), "protocol.log"), - "delay": True - }, - "transportFile": { - "class": "octoprint.logging.handlers.CommunicationLogHandler", - "level": "DEBUG", - "formatter": "communication", - "backupCount": 3, - "filename": os.path.join(settings.getBaseFolder("logs"), "transport.log"), + "filename": os.path.join(settings.getBaseFolder("logs"), "connection.log"), "delay": True }, "commDebugFile": { @@ -282,18 +274,13 @@ def init_logging(settings, use_logging_file=True, logging_file=None, default_con } }, "loggers": { - "PROTOCOL": { - "level": "DEBUG", - "handlers": ["protocolFile"], - "propagate": False - }, - "TRANSPORT": { - "level": "DEBUG", - "handlers": ["transportFile"], + "CONNECTION": { + "level": "INFO", + "handlers": ["connectionFile"], "propagate": False }, "COMMDEBUG": { - "level": "DEBUG", + "level": "INFO", "handlers": ["commDebugFile"], "propagate": False }, diff --git a/src/octoprint/comm/protocol/__init__.py b/src/octoprint/comm/protocol/__init__.py index 079c4ef35..75aee2e8a 100644 --- a/src/octoprint/comm/protocol/__init__.py +++ b/src/octoprint/comm/protocol/__init__.py @@ -71,7 +71,7 @@ class Protocol(ListenerAware, TransportListener): super(Protocol, self).__init__() self._logger = logging.getLogger(__name__) - self._protocol_logger = logging.getLogger("PROTOCOL") + self._connection_logger = logging.getLogger("CONNECTION") self._state = ProtocolState.DISCONNECTED self._error = None @@ -312,7 +312,7 @@ class Protocol(ListenerAware, TransportListener): self.process_protocol_log(message) def process_protocol_log(self, message): - self._protocol_logger.info(message) + self._connection_logger.debug(message) self.notify_listeners("on_protocol_log", self, message) def _job_on_hold_cleared(self): diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 747e0b27c..76a507f9d 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -271,15 +271,14 @@ class Printer(PrinterInterface, ##~~ Logging - if not logging.getLogger("SERIAL").isEnabledFor(logging.DEBUG): - # if serial.log is not enabled, log a line to explain that to reduce "serial.log is empty" in tickets... - logging.getLogger("SERIAL").info("serial.log is currently not enabled, you can enable it via Settings > Serial Connection > Log communication to serial.log") - from octoprint.logging.handlers import CommunicationLogHandler - CommunicationLogHandler.on_open_connection(u"TRANSPORT") - CommunicationLogHandler.on_open_connection(u"PROTOCOL") + CommunicationLogHandler.on_open_connection(u"CONNECTION") CommunicationLogHandler.on_open_connection(u"COMMDEBUG") + if not logging.getLogger("CONNECTION").isEnabledFor(logging.DEBUG): + # is protocol.log is not enabled, log a line to explain to reduce "connection.log is empty" in tickets... + logging.getLogger("CONNECTION").info("connection.log is currently not enabled, you can enable it via Settings > Connection > Log communication to connection.log") + connection_id = kwargs.get("connection") connection = None if connection_id is not None: diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index cac25cb30..eea186202 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -185,6 +185,12 @@ def getSettings(): "capBusyProtocol": s.getBoolean(["serial", "capabilities", "busy_protocol"]), "capEmergencyParser": s.getBoolean(["serial", "capabilities", "emergency_parser"]) }, + "connection": { + "log": { + "connection": s.getBoolean(["connection", "log", "connection"]), + "commdebug": s.getBoolean(["connection", "log", "commdebug"]) + } + }, "folder": { "uploads": s.getBaseFolder("uploads"), "timelapse": s.getBaseFolder("timelapse"), @@ -484,6 +490,28 @@ def _saveSettings(data): logging.getLogger("SERIAL").setLevel(logging.DEBUG) logging.getLogger("SERIAL").debug("Enabling serial logging") + if "connection" in data: + if "log" in data["connection"]: + + def toggle_log(log_type, logger_name): + old_setting = s.getBoolean(["connection", "log", log_type]) + if log_type in data["connection"]["log"]: + s.setBoolean(["connection", "log", log_type], + data["connection"]["log"][log_type] in valid_boolean_trues) + new_setting = s.getBoolean(["connection", "log", log_type]) + + if old_setting and not new_setting: + # disable logging + logging.getLogger(logger_name).debug("Disabling logging") + logging.getLogger(logger_name).setLevel(logging.INFO) + elif not old_setting and new_setting: + # enable logging + logging.getLogger(logger_name).setLevel(logging.DEBUG) + logging.getLogger(logger_name).debug("Enabling logging") + + toggle_log("connection", "CONNECTION") + toggle_log("commdebug", "COMMDEBUG") + if "temperature" in data: if "profiles" in data["temperature"]: result = [] diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index d52c85d7b..2861267d3 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -585,10 +585,8 @@ def fetch_template_data(refresh=False): # settings dialog templates["settings"]["entries"] = dict( - section_printer=(gettext("Printer"), None), - - serial=(gettext("Serial Connection"), dict(template="dialogs/settings/serialconnection.jinja2", _div="settings_serialConnection", custom_bindings=False)), - connectionprofiles=(gettext("Connection Profiles"), dict(template="dialogs/settings/connectionprofiles.jinja2", _div="settings_connectionProfiles", custom_bindings=False)), + section_printer=(gettext("Printer & Connection"), None), + connection=(gettext("Connection"), dict(template="dialogs/settings/connection.jinja2", _div="settings_connection", custom_bindings=False)), printerprofiles=(gettext("Printer Profiles"), dict(template="dialogs/settings/printerprofiles.jinja2", _div="settings_printerProfiles", custom_bindings=False)), temperatures=(gettext("Temperatures"), dict(template="dialogs/settings/temperatures.jinja2", _div="settings_temperature", custom_bindings=False)), terminalfilters=(gettext("Terminal Filters"), dict(template="dialogs/settings/terminalfilters.jinja2", _div="settings_terminalFilters", custom_bindings=False)), diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 7260ca19e..a53d1bc85 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -161,6 +161,12 @@ default_settings = { # command specific flags "triggerOkForM29": True }, + "connection": { + "log": { + "connection": False, + "commdebug": False + } + }, "server": { "host": None, "port": 5000, @@ -314,7 +320,7 @@ default_settings = { "sidebar": ["plugin_printer_safety_check", "connection", "state", "files"], "tab": ["temperature", "control", "gcodeviewer", "terminal", "timelapse"], "settings": [ - "section_printer", "serial", "connectionprofiles", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts", + "section_printer", "connection", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts", "section_features", "features", "webcam", "accesscontrol", "gcodevisualizer", "api", "plugin_appkeys", "section_octoprint", "server", "folders", "appearance", "plugin_logging", "plugin_pluginmanager", "plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_errortracking", diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index e9c96d1e3..7e7d59a92 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -203,6 +203,9 @@ $(function() { self.serial_capBusyProtocol = ko.observable(undefined); self.serial_capEmergencyParser = ko.observable(undefined); + self.connection_log_connection = ko.observable(undefined); + self.connection_log_commdebug = ko.observable(undefined); + self.folder_uploads = ko.observable(undefined); self.folder_timelapse = ko.observable(undefined); self.folder_timelapseTmp = ko.observable(undefined); diff --git a/src/octoprint/templates/dialogs/settings/connection.jinja2 b/src/octoprint/templates/dialogs/settings/connection.jinja2 new file mode 100644 index 000000000..ba90a64e5 --- /dev/null +++ b/src/octoprint/templates/dialogs/settings/connection.jinja2 @@ -0,0 +1,59 @@ +
+ + +
+
+
+ {{ _('Logging') }} +
+
+ +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + +
+
+
diff --git a/src/octoprint/templates/dialogs/settings/connectionprofiles.jinja2 b/src/octoprint/templates/dialogs/settings/connectionprofiles.jinja2 deleted file mode 100644 index 90411d2bc..000000000 --- a/src/octoprint/templates/dialogs/settings/connectionprofiles.jinja2 +++ /dev/null @@ -1,30 +0,0 @@ -

{{ _('Connection Profiles') }}

- - - - - - - - - - - - - - - - - diff --git a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 b/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 deleted file mode 100644 index b180c8ddb..000000000 --- a/src/octoprint/templates/dialogs/settings/serialconnection.jinja2 +++ /dev/null @@ -1,435 +0,0 @@ -
- - -
-
-
- {{ _('Connection') }} -
- -
- -
-
-
- -
- -
-
-
-
- -
-
-
- -
- - {{ _('Use this to define additional glob patterns matching serial ports to list for connecting against, e.g. /dev/ttyAMA*. One entry per line.')|format(glob_url="http://docs.python.org/2/library/glob.html") }} -
-
-
- -
- - {{ _('Use this to define additional serial port baud rates to list for connecting with, e.g. 123456. Comma separated.') }} -
-
-
-
- -
-
-
-
- {{ _('Serial logging') }} -
-
- -
-
-
-
-
-
- {{ _('Query intervals') }} -
- -
-
- - s -
- {{ _('When printing or idle')}} -
-
-
- - s -
- {{ _('When idle and a target temperature is set')}} -
-
-
- -
-
- - s -
- {{ _('Autoreport interval to request from firmware')}} -
-
-
- -
-
- - s -
- {{ _('When printing from the printer\'s SD')}} -
-
-
- -
-
- - s -
- {{ _('Autoreport interval to request from firmware')}} -
-
-
-
- {{ _('Timeouts') }} -
- -
-
- - s -
- {{ _('busy protocol support not detected')}} -
-
-
- - s -
- {{ _('busy protocol support detected')}} -
-
-
- -
-
- - s -
-
-
-
- -
-
- - s -
-
-
-
- -
-
- - s -
-
-
-
- -
-
- -
-
- - s -
- {{ _('Some controllers need a bit of a breather before baudrate detection after initial connect. If baudrate detection fails due to a hanging controller, try increasing this value.') }} -
-
-
- -
- - {{ _('Set to 0 to disable consecutive timeout detection and handling.') }} -
-
-
- -
- - {{ _('Set to 0 to disable consecutive timeout detection and handling.') }} -
-
-
- -
- - {{ _('Set to 0 to disable consecutive timeout detection and handling.') }} -
-
-
-
-
-
-
-
- {{ _('Firmware specific settings') }} -
-
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
- - - -
-
-
-
- -
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
- -
- - - - {{ _('Some Marlin forks lack an acknowledging ok with their resend requests. Set this to "always" or "if detected as necessary" if you run into communication stalls on resend requests.') }} -
-
-
-
-
-
- {{ _('Protocol fine tuning') }} -
-
- -
-
-
- -
- - {{ _('Use this to specify commands that should never be sent to the printer. Just the G or M code, comma separated. Defaults to M0 and M1 since most firmware will block until a button on the controller has been pressed if it receives either of those two commands.') }} -
-
-
- -
- - {{ _('Use this to specify commands on which OctoPrint should pause the print job. Just the G or M code, comma separated. Defaults to M0, M1 and M25.') }} -
-
-
- -
- - {{ _('Use this to specify emergency commands which should jump any queues and - if supported by the firmware - be force sent. Just the G or M code, comma separated. Defaults to M112, M118 and M410.') }}
-
-
- -
-
- -
- - {{ _('Use this to specify a different command than the default M110 to send to the printer on initial connection to trigger a communication handshake.') }} -
-
-
- -
- - {{ _('Use this to specify the commands known to take a long time to complete without output from your printer and hence might cause timeout issues. Just the G or M code, comma separated.') }} -
-
-
- -
- - {{ _('Use this to specify which commands always need to be sent with a checksum. Comma separated list.') }} -
-
-
-
-
-
-
-
- {{ _('Error handling') }} -
- -
- - - -
-
-
-
- {{ _('Pausing') }} -
- -
-
-
- {{ _('Cancelling') }} -
- -
-
- -
-
-
-
-