logging: exceptions can log more info

This commit is contained in:
alfrix 2022-05-14 17:04:50 -03:00 committed by Alfredo Monclus
parent 7c8d4ea4d7
commit 562e49b8d2
4 changed files with 15 additions and 8 deletions

View File

@ -34,7 +34,8 @@ class KlippyRest:
headers = {} if self.api_key is False else {"x-api-key": self.api_key}
try:
r = requests.get(url, headers=headers)
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
return False
if r.status_code != 200:
return False
@ -42,7 +43,8 @@ class KlippyRest:
# TODO: Try/except
try:
data = json.loads(r.content)
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
logging.exception("Unable to parse response from moonraker:\n %s" % r.content)
return False

View File

@ -74,7 +74,8 @@ class KlippyWebsocket(threading.Thread):
_("Retry #%s") % self.reconnect_count)
return False
token = self._screen.apiclient.get_oneshot_token()
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
logging.debug("Unable to get oneshot token")
return False
@ -86,7 +87,8 @@ class KlippyWebsocket(threading.Thread):
try:
logging.debug("Starting websocket thread")
self._wst.start()
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
logging.debug("Error starting web socket")
def close(self):

View File

@ -64,7 +64,8 @@ def get_wireless_interfaces():
try:
p = subprocess.Popen(["iwconfig"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = p.stdout.read().decode('ascii').split('\n')
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
logging.info("Error with running iwconfig command")
return None
interfaces = []

View File

@ -50,8 +50,9 @@ class WifiManager():
self.soc = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
self.soc.bind(KS_SOCKET_FILE)
self.soc.connect("/var/run/wpa_supplicant/%s" % interface)
except Exception:
logging.info("Error connecting to wifi socket: %s" % interface)
except Exception as e:
logging.critical(e, exc_info=True)
logging.error("Error connecting to wifi socket: %s" % interface)
return
self.wpa_thread = WpaSocket(self, self.queue, self.callback)
@ -324,7 +325,8 @@ class WpaSocket(Thread):
while self._stop_loop is False:
try:
msg = self.soc.recv(4096).decode().strip()
except Exception:
except Exception as e:
logging.critical(e, exc_info=True)
# TODO: Socket error
continue
if msg.startswith("<"):