Logging improvements

This commit is contained in:
Matthew Stratford 2021-09-08 23:36:59 +01:00
parent 8a66ad86e6
commit 10c33af133
4 changed files with 6 additions and 8 deletions

View file

@ -375,8 +375,7 @@ class MyRadioAPI:
self._log("Ending tracklistitemid {}".format(tracklistitemid)) self._log("Ending tracklistitemid {}".format(tracklistitemid))
result = self.api_call("/tracklistItem/{}/endtime".format(tracklistitemid), method="PUT") self.api_call("/tracklistItem/{}/endtime".format(tracklistitemid), method="PUT")
print(result)
def _log(self, text: str, level: int = INFO): def _log(self, text: str, level: int = INFO):
self.logger.log.log(level, "MyRadio API: " + text) self.logger.log.log(level, "MyRadio API: " + text)

View file

@ -36,7 +36,7 @@ class StateManager:
# Try creating the directory. # Try creating the directory.
os.mkdir(path_dir) os.mkdir(path_dir)
except Exception: except Exception:
print("Failed to create state directory.") self._logException("Failed to create state directory.")
return return
self.filepath = resolve_external_file_path("/state/" + name + ".json") self.filepath = resolve_external_file_path("/state/" + name + ".json")
@ -48,7 +48,7 @@ class StateManager:
# Try creating the file. # Try creating the file.
open(self.filepath, "x") open(self.filepath, "x")
except Exception: except Exception:
self._log("Failed to create state file.", CRITICAL) self._logException("Failed to create state file.")
return return
file_raw: str file_raw: str

View file

@ -43,7 +43,7 @@
{% endfor %} {% endfor %}
<br> <br>
{% else %} {% else %}
<p>RIP. Failed to get this.</p> <p>Failed to get status from Player Channel. Channel may be busy or has failed.</p>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endfor %}

View file

@ -59,7 +59,7 @@ class WebsocketServer:
_exit(0) _exit(0)
def __del__(self): def __del__(self):
print("Deleting websocket server") self.logger.log.info("Deleting websocket server")
self.quit() self.quit()
async def websocket_handler(self, websocket, path): async def websocket_handler(self, websocket, path):
@ -225,7 +225,6 @@ class WebsocketServer:
continue continue
command = message.split(":")[1] command = message.split(":")[1]
# print("Websocket Out:", command)
if command == "STATUS": if command == "STATUS":
try: try:
message = message.split("OKAY:")[1] message = message.split("OKAY:")[1]
@ -263,4 +262,4 @@ class WebsocketServer:
if __name__ == "__main__": if __name__ == "__main__":
print("Don't do this") raise Exception("Don't run this file standalone.")