Change prints to logs

This commit is contained in:
Kumi 2021-11-30 17:52:40 +01:00
parent 579abf3afc
commit c5a5500654
3 changed files with 13 additions and 6 deletions

View file

@ -15,4 +15,7 @@ class Logger:
print(self.__class__()._format(message, "DEBUG")) print(self.__class__()._format(message, "DEBUG"))
def info(self, message: str) -> None: def info(self, message: str) -> None:
print(self.__class__()._format(message, "INFO")) print(self.__class__()._format(message, "INFO"))
def error(self, message: str) -> None:
print(self.__class__()._format(message, "ERROR"))

View file

@ -1,6 +1,9 @@
from paramiko.ssh_exception import SSHException, NoValidConnectionsError from paramiko.ssh_exception import SSHException, NoValidConnectionsError
from socket import timeout from socket import timeout
from classes.logger import Logger
class retry: class retry:
"""Decorator used to automatically retry operations throwing exceptions """Decorator used to automatically retry operations throwing exceptions
""" """
@ -15,6 +18,7 @@ class retry:
""" """
self.exceptions = exceptions or (SSHException, NoValidConnectionsError, self.exceptions = exceptions or (SSHException, NoValidConnectionsError,
timeout, TimeoutError) timeout, TimeoutError)
self._logger = Logger()
def __call__(self, f): def __call__(self, f):
"""Return a function through the retry decorator """Return a function through the retry decorator
@ -30,6 +34,6 @@ class retry:
try: try:
return f(*args, **kwargs) return f(*args, **kwargs)
except self.exceptions as e: except self.exceptions as e:
print("Caught expected exception: " + repr(e)) self._logger.info("Caught expected exception: " + repr(e))
return wrapped_f return wrapped_f

View file

@ -31,22 +31,22 @@ class VesselThread(Process):
def run(self) -> NoReturn: def run(self) -> NoReturn:
"""Run thread and process uploads to the vessel """Run thread and process uploads to the vessel
""" """
print("Launched Vessel Thread for " + self.vessel.name) self._logger.debug("Launched Vessel Thread for " + self.vessel.name)
self.assertDirectories() self.assertDirectories()
while True: while True:
try: try:
self.upload() self.upload()
time.sleep(5) time.sleep(5)
except Exception as e: except Exception as e:
print("An exception occurred in the Vessel Thread for " + self._logger.error("An exception occurred in the Vessel Thread for " +
self.vessel.name) self.vessel.name)
print(repr(e)) self._logger.error(repr(e))
@retry() @retry()
def assertDirectories(self) -> None: def assertDirectories(self) -> None:
for directory in self._state["config"].directories: for directory in self._state["config"].directories:
if not directory.name in self.vessel._ignoredirs: if not directory.name in self.vessel._ignoredirs:
print( self._logger.debug(
f"Making sure directory {directory.name} exists on Vessel {self.vessel.name}") f"Making sure directory {directory.name} exists on Vessel {self.vessel.name}")
self.vessel.connection.assertDirectories(directory) self.vessel.connection.assertDirectories(directory)