From 4f8f92e8c14da18d9feb694aa605a6c7c69b9c87 Mon Sep 17 00:00:00 2001 From: Sergei Zobov Date: Sat, 10 Oct 2020 22:56:33 +0300 Subject: [PATCH] Refactoring: Logging in more friendly way --- octoprint_telegram/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/octoprint_telegram/__init__.py b/octoprint_telegram/__init__.py index 7133176..97f34c2 100644 --- a/octoprint_telegram/__init__.py +++ b/octoprint_telegram/__init__.py @@ -83,7 +83,7 @@ def loop(self): raise exit #wooooops. can't handle the message except Exception as ex: - self._logger.error("Exception caught! " + str(ex)) + self._logger.exception("Exception caught! " + str(ex)) self.set_status(gettext("Connected as %(username)s.", username=self.username), ok=True) # we had first contact after octoprint startup # so lets send startup message @@ -866,7 +866,7 @@ def on_settings_migrate(self, target, current=None): try: self._settings.save() except Exception as ex: - self._logger.error("MIGRATED Save failed - " + str(ex)) + self._logger.exception("MIGRATED Save failed - " + str(ex)) self._logger.debug("MIGRATED Saved") @@ -1158,9 +1158,9 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None, self.send_file(chatID, ret,"") sendOneInLoop = True except Exception as ex: - self._logger.error("Exception loop multicam URL to create gif: "+ str(ex) ) + self._logger.exception("Exception loop multicam URL to create gif: "+ str(ex) ) except Exception as ex: - self._logger.error("Exception occured on getting multicam options: "+ str(ex) ) + self._logger.exception("Exception occured on getting multicam options: "+ str(ex) ) else: ret = self.create_gif_new(chatID,0,0) @@ -1249,11 +1249,11 @@ def _send_msg(self, message="", with_image=False,with_gif=False,responses=None, self._logger.debug("url is the same as the one from octoprint " ) except Exception as ex: - self._logger.error("Exception loop multicam URL to create image: "+ str(ex) ) + self._logger.exception("Exception loop multicam URL to create image: "+ str(ex) ) except Exception as ex: - self._logger.error("Exception occured on getting multicam options: "+ str(ex) ) + self._logger.exception("Exception occured on getting multicam options: "+ str(ex) ) except Exception as ex: - self._logger.error("Exception occured on getting multicam plugin: "+ str(ex) ) + self._logger.exception("Exception occured on getting multicam plugin: "+ str(ex) ) if r is not None and inline: r.raise_for_status() @@ -1348,7 +1348,7 @@ def get_usrPic(self,chat_id, file_id=""): self._logger.debug("Saved Photo "+ str(chat_id)) except Exception as ex: - self._logger.error("Can't load UserImage: " + str(ex)) + self._logger.exception("Can't load UserImage: " + str(ex)) def test_token(self, token=None): if not self.send_messages: @@ -1414,7 +1414,7 @@ def take_image(self,snapshot_url=""): r = requests.get(snapshot_url,timeout=10) data = r.content except Exception as e: - self._logger.error("TimeOut Exception: " + str(e)) + self._logger.exception("TimeOut Exception: " + str(e)) return None flipH = self._settings.global_get(["webcam", "flipH"]) flipV = self._settings.global_get(["webcam", "flipV"]) @@ -1460,7 +1460,7 @@ def calculate_ETA(self,printTime = 0): else: strtime = " " + format_date(finish_time,"EEE d") except Exception as ex: - self._logger.error("An Exception in get final time : " + str(ex) ) + self._logger.exception("An Exception in get final time : " + str(ex) ) return strtime + strdate