commit b3c80ccbe62ddac32fcd422ff4443013197a4fd6
Author: David Friesecký <frieseck@students.zcu.cz>
Date:   Fri Apr 23 22:31:17 2021 +0200

    Re #8570 - Added logs

diff --git a/src/dao/certificate_repository.py b/src/dao/certificate_repository.py
index e4039e0..0ef4742 100644
--- a/src/dao/certificate_repository.py
+++ b/src/dao/certificate_repository.py
@@ -1,4 +1,4 @@
-from sqlite3 import Connection, Error
+from sqlite3 import Connection, Error, DatabaseError, IntegrityError, ProgrammingError, OperationalError, NotSupportedError
 from typing import Dict, List
 
 from src.exceptions.database_exception import DatabaseException
@@ -7,6 +7,13 @@ from src.constants import *
 from src.model.certificate import Certificate
 from src.utils.logger import Logger
 
+INTEGRITY_ERROR_MSG = "Database relational integrity corrupted."
+PROGRAMMING_ERROR_MSG = "Exception raised for programming errors (etc. SQL statement)."
+OPERATIONAL_ERROR_MSG = "Exception raised for errors that are related to the database’s operation."
+NOT_SUPPORTED_ERROR_MSG = "Method or database API was used which is not supported by the database"
+DATABASE_ERROR_MSG = "Unknown exception that are related to the database."
+ERROR_MSG = "Unknown exception."
+
 
 class CertificateRepository:
 
@@ -30,6 +37,8 @@ class CertificateRepository:
         :return: the result of whether the creation was successful
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"INSERT INTO {TAB_CERTIFICATES} "
                    f"({COL_COMMON_NAME},"
@@ -66,8 +75,24 @@ class CertificateRepository:
                         values = [last_id, usage_id]
                         self.cursor.execute(sql, values)
                         self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return last_id
 
@@ -80,6 +105,8 @@ class CertificateRepository:
         :return: instance of the Certificate object
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
                    f"WHERE {COL_ID} = ?")
@@ -110,8 +137,24 @@ class CertificateRepository:
                                                    usage_dict,
                                                    certificate_row[5],
                                                    certificate_row[6])
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return certificate
 
@@ -124,6 +167,8 @@ class CertificateRepository:
         :return: list of certificates
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql_extension = ""
             values = []
@@ -159,8 +204,24 @@ class CertificateRepository:
                                                 usage_dict,
                                                 certificate_row[5],
                                                 certificate_row[6]))
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return certificates
 
@@ -176,6 +237,8 @@ class CertificateRepository:
         :return: the result of whether the updation was successful
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"UPDATE {TAB_CERTIFICATES} "
                    f"SET {COL_COMMON_NAME} = ?, "
@@ -213,8 +276,24 @@ class CertificateRepository:
                     values = [certificate_id, usage_id]
                     self.cursor.execute(sql, values)
                     self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
 
@@ -227,14 +306,32 @@ class CertificateRepository:
         :return: the result of whether the deletion was successful
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"DELETE FROM {TAB_CERTIFICATES} "
                    f"WHERE {COL_ID} = ?")
             values = [certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
 
@@ -252,6 +349,8 @@ class CertificateRepository:
             sqlite3.Error if an exception is thrown
         """
 
+        Logger.debug("Function launched.")
+
         try:
             if revocation_date != "" and revocation_reason == "":
                 revocation_reason = REV_REASON_UNSPECIFIED
@@ -267,8 +366,24 @@ class CertificateRepository:
                       certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
 
@@ -283,6 +398,8 @@ class CertificateRepository:
             sqlite3.Error if an exception is thrown
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"UPDATE {TAB_CERTIFICATES} "
                    f"SET {COL_REVOCATION_DATE} = '', "
@@ -291,8 +408,24 @@ class CertificateRepository:
             values = [certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
 
@@ -308,6 +441,8 @@ class CertificateRepository:
             sqlite3.Error if an exception is thrown
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
                    f"WHERE {COL_PARENT_ID} = ? AND {COL_REVOCATION_DATE} IS NOT NULL AND {COL_REVOCATION_DATE} != ''")
@@ -338,8 +473,24 @@ class CertificateRepository:
                                                 usage_dict,
                                                 certificate_row[5],
                                                 certificate_row[6]))
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return certificates
 
@@ -355,6 +506,8 @@ class CertificateRepository:
             sqlite3.Error if an exception is thrown
         """
 
+        Logger.debug("Function launched.")
+
         try:
             sql = (f"SELECT * FROM {TAB_CERTIFICATES} "
                    f"WHERE {COL_PARENT_ID} = ? AND {COL_ID} != ?")
@@ -385,8 +538,24 @@ class CertificateRepository:
                                                 usage_dict,
                                                 certificate_row[5],
                                                 certificate_row[6]))
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return certificates
 
@@ -397,17 +566,40 @@ class CertificateRepository:
         :param certificate_id: target certificate ID
         :return: list of all descendants
         """
-        def dfs(children_of, this, collection: list):
-            for child in children_of(this.certificate_id):
-                dfs(children_of, child, collection)
-            collection.append(this)
 
-        subtree_root = self.read(certificate_id)
-        if subtree_root is None:
-            return None
+        Logger.debug("Function launched.")
+
+        try:
+            def dfs(children_of, this, collection: list):
+                for child in children_of(this.certificate_id):
+                    dfs(children_of, child, collection)
+                collection.append(this)
+
+            subtree_root = self.read(certificate_id)
+            if subtree_root is None:
+                return None
+
+            all_certs = []
+            dfs(self.get_all_issued_by, subtree_root, all_certs)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
-        all_certs = []
-        dfs(self.get_all_issued_by, subtree_root, all_certs)
         return all_certs
 
     def get_next_id(self) -> int:
@@ -415,13 +607,36 @@ class CertificateRepository:
         Get identifier of the next certificate that will be inserted into the database
         :return: identifier of the next certificate that will be added into the database
         """
-        # get next IDs of all tables
-        self.cursor.execute("SELECT * FROM SQLITE_SEQUENCE")
-        results = self.cursor.fetchall()
-
-        # search for next ID in Certificates table and return it
-        for result in results:
-            if result[0] == TAB_CERTIFICATES:
-                return result[1] + 1  # current last id + 1
-        # if certificates table is not present in the query results, return 1
+
+        Logger.debug("Function launched.")
+
+        try:
+            # get next IDs of all tables
+            self.cursor.execute("SELECT * FROM SQLITE_SEQUENCE")
+            results = self.cursor.fetchall()
+
+            # search for next ID in Certificates table and return it
+            for result in results:
+                if result[0] == TAB_CERTIFICATES:
+                    return result[1] + 1  # current last id + 1
+            # if certificates table is not present in the query results, return 1
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
+
         return 1
diff --git a/src/dao/private_key_repository.py b/src/dao/private_key_repository.py
index a2ea3a1..c6d453c 100644
--- a/src/dao/private_key_repository.py
+++ b/src/dao/private_key_repository.py
@@ -1,4 +1,4 @@
-from sqlite3 import Connection, Cursor, Error
+from sqlite3 import Connection, Error, DatabaseError, IntegrityError, ProgrammingError, OperationalError, NotSupportedError
 from typing import List
 
 from injector import inject
@@ -6,6 +6,14 @@ from injector import inject
 from src.exceptions.database_exception import DatabaseException
 from src.model.private_key import PrivateKey
 from src.constants import *
+from src.utils.logger import Logger
+
+INTEGRITY_ERROR_MSG = "Database relational integrity corrupted."
+PROGRAMMING_ERROR_MSG = "Exception raised for programming errors (etc. SQL statement)."
+OPERATIONAL_ERROR_MSG = "Exception raised for errors that are related to the database’s operation."
+NOT_SUPPORTED_ERROR_MSG = "Method or database API was used which is not supported by the database"
+DATABASE_ERROR_MSG = "Unknown exception that are related to the database."
+ERROR_MSG = "Unknown exception."
 
 
 class PrivateKeyRepository:
@@ -41,8 +49,24 @@ class PrivateKeyRepository:
             self.cursor.execute(sql, values)
             last_id = self.cursor.lastrowid
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return last_id
 
@@ -68,8 +92,24 @@ class PrivateKeyRepository:
             private_key: PrivateKey = PrivateKey(private_key_row[0],
                                                  private_key_row[1],
                                                  private_key_row[2])
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return private_key
 
@@ -90,8 +130,24 @@ class PrivateKeyRepository:
                 private_keys.append(PrivateKey(private_key_row[0],
                                                private_key_row[1],
                                                private_key_row[2]))
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return private_keys
 
@@ -115,8 +171,24 @@ class PrivateKeyRepository:
                       private_key_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException(e)
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
 
@@ -135,7 +207,23 @@ class PrivateKeyRepository:
             values = [private_key_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except Error as e:
-            raise DatabaseException
+        except IntegrityError:
+            Logger.error(INTEGRITY_ERROR_MSG)
+            raise DatabaseException(INTEGRITY_ERROR_MSG)
+        except ProgrammingError:
+            Logger.error(PROGRAMMING_ERROR_MSG)
+            raise DatabaseException(PROGRAMMING_ERROR_MSG)
+        except OperationalError:
+            Logger.error(OPERATIONAL_ERROR_MSG)
+            raise DatabaseException(OPERATIONAL_ERROR_MSG)
+        except NotSupportedError:
+            Logger.error(NOT_SUPPORTED_ERROR_MSG)
+            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
+        except DatabaseError:
+            Logger.error(DATABASE_ERROR_MSG)
+            raise DatabaseException(DATABASE_ERROR_MSG)
+        except Error:
+            Logger.error(ERROR_MSG)
+            raise DatabaseException(ERROR_MSG)
 
         return self.cursor.rowcount > 0
diff --git a/src/services/certificate_service.py b/src/services/certificate_service.py
index 8e645b8..c4b321c 100644
--- a/src/services/certificate_service.py
+++ b/src/services/certificate_service.py
@@ -16,6 +16,8 @@ from src.services.cryptography import CryptographyService
 
 import time
 
+from src.utils.logger import Logger
+
 VALID_FROM_TO_DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
 CA_EXTENSIONS = "basicConstraints=critical,CA:TRUE"
 CRL_EXTENSION = "crlDistributionPoints=URI:"
@@ -47,6 +49,9 @@ class CertificateService:
         :param days: Number of days for which the generated cert. will be considered valid
         :return: An instance of Certificate class representing the generated root CA cert
         """
+
+        Logger.debug("Function launched.")
+
         if usages is None:
             usages = {}
 
@@ -81,6 +86,9 @@ class CertificateService:
         :param cert_type: Type of this certificate (see constants.py)
         :return: An instance of the Certificate class wrapping the values passed  via method parameters
         """
+
+        Logger.debug("Function launched.")
+
         # parse the generated pem for subject and notBefore/notAfter fields
         # TODO this could be improved in the future in such way that calling openssl is not required to parse the dates
         subj, not_before, not_after = self.cryptography_service.parse_cert_pem(cert_pem)
@@ -108,6 +116,9 @@ class CertificateService:
         :param days: Number of days for which the generated cert. will be considered valid
         :return: An instance of Certificate class representing the generated intermediate CA cert
         """
+
+        Logger.debug("Function launched.")
+
         if usages is None:
             usages = {}
 
@@ -168,6 +179,9 @@ class CertificateService:
         :param days: Number of days for which the generated cert. will be considered valid
         :return: An instance of Certificate class representing the generated cert
         """
+
+        Logger.debug("Function launched.")
+
         if usages is None:
             usages = {}
 
@@ -204,6 +218,9 @@ class CertificateService:
         :return: Instance of the Certificate class containing a certificate with the given id or `None` if such
         certificate is not found
         """
+
+        Logger.debug("Function launched.")
+
         return self.certificate_repository.read(unique_id)
 
     def get_certificates(self, cert_type=None) -> List[Certificate]:
@@ -214,6 +231,9 @@ class CertificateService:
         :return: List of instances of the Certificate class representing all certificates present in the certificate
         repository. An empty list is returned when no certificates are found.
         """
+
+        Logger.debug("Function launched.")
+
         return self.certificate_repository.read_all(cert_type)
 
     def get_chain_of_trust(self, from_id: int, to_id: int = -1, exclude_root=True) -> List[Certificate]:
@@ -226,6 +246,9 @@ class CertificateService:
         :return: a list of certificates representing the chain of trust starting with the certificate given by `from_id`
         ID
         """
+
+        Logger.debug("Function launched.")
+
         # read the first certificate of the chain
         start_cert = self.certificate_repository.read(from_id)
 
@@ -273,19 +296,24 @@ class CertificateService:
         :param unique_id: ID of specific certificate
         """
 
+        Logger.debug("Function launched.")
+
         to_delete = self.certificate_repository.get_all_descendants_of(unique_id)
         if to_delete is None:
+            Logger.error(f"No such certificate found 'ID = {unique_id}'.")
             raise CertificateNotFoundException(unique_id)
 
         for cert in to_delete:
             try:
                 self.set_certificate_revocation_status(cert.certificate_id, STATUS_REVOKED)
             except CertificateAlreadyRevokedException:
+                Logger.info(f"Certificate already revoked 'ID = {unique_id}'.")
                 # TODO log as an info/debug, not warning or above <-- perfectly legal
                 pass
 
-            self.certificate_repository.delete(cert.certificate_id)
-            # TODO log if not successfully deleted
+            if not self.certificate_repository.delete(cert.certificate_id):
+                Logger.error(f"The certificate has not been deleted 'ID = {cert.certificate_id}'.")
+
 
     def get_certificates_issued_by(self, unique_id):
         """
@@ -294,10 +322,15 @@ class CertificateService:
         :param unique_id: target certificate ID
         :return: children of unique_id
         """
+
+        Logger.debug("Function launched.")
+
         try:
             if self.certificate_repository.read(unique_id) is None:
+                Logger.error(f"No such certificate found 'ID = {unique_id}'.")
                 raise CertificateNotFoundException(unique_id)
         except DatabaseException:
+            Logger.error(f"No such certificate found 'ID = {unique_id}'.")
             raise CertificateNotFoundException(unique_id)
 
         return self.certificate_repository.get_all_issued_by(unique_id)
@@ -310,14 +343,20 @@ class CertificateService:
         :param id: identifier of the certificate whose status is to be changed
         :param status: new status of the certificate
         """
+
+        Logger.debug("Function launched.")
+
         if status not in CERTIFICATE_STATES:
+            Logger.error(f"Wrong parameter, invalid status '{status}'.")
             raise CertificateStatusInvalidException(status)
         if reason not in CERTIFICATE_REVOCATION_REASONS:
+            Logger.error(f"Wrong parameter, invalid reason '{reason}'.")
             raise RevocationReasonInvalidException(reason)
 
         # check whether the certificate exists
         certificate = self.certificate_repository.read(id)
         if certificate is None:
+            Logger.error(f"No such certificate found 'ID = {id}'.")
             raise CertificateNotFoundException(id)
 
         updated = False
@@ -327,13 +366,15 @@ class CertificateService:
             # check if the certificate is not revoked already
             revoked = self.certificate_repository.get_all_revoked_by(certificate.parent_id)
             if certificate.certificate_id in [x.certificate_id for x in revoked]:
+                Logger.error(f"Certificate already revoked 'ID = {id}'.")
                 raise CertificateAlreadyRevokedException(id)
 
             revocation_timestamp = int(time.time())
             updated = self.certificate_repository.set_certificate_revoked(id, str(revocation_timestamp), reason)
 
         if not updated:
-            # TODO log this
+            Logger.error(f"Repository returned 'false' from clear_certificate_revocation() "
+                         f"or set_certificate_revoked().")
             raise UnknownException("Repository returned 'false' from clear_certificate_revocation() "
                                    "or set_certificate_revoked().")
 
@@ -343,6 +384,9 @@ class CertificateService:
         :param certificate: certificate instance whose Subject shall be parsed
         :return: instance of Subject class containing resulting distinguished name
         """
+
+        Logger.debug("Function launched.")
+
         (subject, _, _) = self.cryptography_service.parse_cert_pem(certificate.pem_data)
         return subject
 
@@ -353,6 +397,9 @@ class CertificateService:
         should be extracted.
         :return: a string containing the extracted public key in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         return self.cryptography_service.extract_public_key_from_certificate(certificate.pem_data)
 
     def __get_crl_endpoint(self, ca_identifier: int) -> str:
@@ -363,6 +410,9 @@ class CertificateService:
         :param ca_identifier: ID of issuing authority
         :return: CRL endpoint for the given CA
         """
+
+        Logger.debug("Function launched.")
+
         return self.configuration.base_server_url + "/api/crl/" + str(ca_identifier)
 
     def __get_ocsp_endpoint(self, ca_identifier: int) -> str:
@@ -373,6 +423,9 @@ class CertificateService:
         :param ca_identifier: ID of issuing authority
         :return: OCSP endpoint for the given CA
         """
+
+        Logger.debug("Function launched.")
+
         return self.configuration.base_server_url + "/api/ocsp/" + str(ca_identifier)
 
 
diff --git a/src/services/cryptography.py b/src/services/cryptography.py
index 25663f6..cb28a5c 100644
--- a/src/services/cryptography.py
+++ b/src/services/cryptography.py
@@ -7,6 +7,7 @@ from src.constants import CRL_CONFIG
 from src.model.certificate import Certificate
 from src.model.private_key import PrivateKey
 from src.model.subject import Subject
+from src.utils.logger import Logger
 from src.utils.temporary_file import TemporaryFile
 
 # encryption method to be used when generating private keys
@@ -41,6 +42,9 @@ class CryptographyService:
         :param subject: subject to be converted
         :return: a dictionary containing openssl field names mapped to subject's fields
         """
+
+        Logger.debug("Function launched.")
+
         subj_dict = {}
         if subject.common_name is not None:
             subj_dict["CN"] = subject.common_name
@@ -71,6 +75,9 @@ class CryptographyService:
         :param executable: Executable to be run (defaults to openssl)
         :return: If the process ends with a zero return code then the STDOUT of the process is returned as a byte array.
         """
+
+        Logger.debug("Function launched.")
+
         if args is None:
             args = []
         try:
@@ -87,13 +94,16 @@ class CryptographyService:
             if proc.returncode != 0:
                 # if the process did not result in zero result code, then raise an exception
                 if err is not None and len(err) > 0:
+                    Logger.error("CryptographyException")
                     raise CryptographyException(executable, args, err.decode())
                 else:
+                    Logger.error("CryptographyException")
                     raise CryptographyException(executable, args,
                                                 f""""Execution resulted in non-zero argument""")
 
             return out
         except FileNotFoundError:
+            Logger.error("CryptographyException")
             raise CryptographyException(executable, args, f""""{executable}" not found in the current PATH.""")
 
     def create_private_key(self, passphrase=None):
@@ -103,6 +113,9 @@ class CryptographyService:
         encrypted at all). Empty passphrase ("") also results in a key that is not encrypted.
         :return: string containing the generated private key in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         if passphrase is None or len(passphrase) == 0:
             return self.__run_for_output(["genrsa", "2048"]).decode()
         else:
@@ -123,6 +136,9 @@ class CryptographyService:
 
         :return: string containing the generated certificate in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         assert key is not None
         assert subject is not None
 
@@ -170,6 +186,8 @@ class CryptographyService:
         :return: string containing the generated certificate signing request in PEM format
         """
 
+        Logger.debug("Function launched.")
+
         subj_param = self.__subject_to_param_format(subject)
 
         args = ["req", "-new", "-subj", subj_param, "-key", "-"]
@@ -195,6 +213,8 @@ class CryptographyService:
         :return: string containing the generated and signed certificate in PEM format
         """
 
+        Logger.debug("Function launched.")
+
         # concatenate CSR, issuer certificate and issuer's key (will be used in the openssl call)
         proc_input = csr + issuer_pem + issuer_key
 
@@ -238,6 +258,9 @@ class CryptographyService:
         :param sn: serial number to be set, when "None" is set a random serial number is generated
         :return: string containing the generated certificate in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         csr = self.__create_csr(subject, subject_key, key_pass=subject_key_pass)
         return self.__sign_csr(csr, issuer_pem, issuer_key, issuer_key_pass=issuer_key_pass, extensions=extensions,
                                days=days, sn=sn)
@@ -250,6 +273,9 @@ class CryptographyService:
         :param certificate: certificate to be verified in PEM format
         :return: Returns `true` if the certificate is not expired, `false` when expired.
         """
+
+        Logger.debug("Function launched.")
+
         # call openssl to check whether the certificate is valid to this date
         args = [OPENSSL_EXECUTABLE, "x509", "-checkend", "0", "-noout", "-text", "-in", "-"]
 
@@ -268,6 +294,7 @@ class CryptographyService:
             return False
         else:
             # the process failed because of some other reason (incorrect cert format)
+            Logger.error("CryptographyException")
             raise CryptographyException(OPENSSL_EXECUTABLE, args, err.decode())
 
     def extract_public_key_from_private_key(self, private_key_pem: str, passphrase=None) -> str:
@@ -277,6 +304,9 @@ class CryptographyService:
         :param passphrase: passphrase to be provided when the supplied private key is encrypted
         :return: a string containing the extracted public key in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         args = ["rsa", "-in", "-", "-pubout"]
         if passphrase is not None:
             args.extend(["-passin", f"pass:{passphrase}"])
@@ -288,6 +318,9 @@ class CryptographyService:
         :param cert_pem: PEM data representing a certificate from which a public key should be extracted
         :return: a string containing the extracted public key in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         # extracting public key from a certificate does not seem to require a passphrase even when
         # signed using an encrypted PK
         args = ["x509", "-in", "-", "-noout", "-pubkey"]
@@ -300,6 +333,9 @@ class CryptographyService:
         :param cert_pem: a certificated in a PEM format to be parsed
         :return: a tuple containing a subject, NOT_BEFORE and NOT_AFTER dates
         """
+
+        Logger.debug("Function launched.")
+
         # run openssl x509 to view certificate content
         args = ["x509", "-noout", "-subject", "-startdate", "-enddate", "-in", "-"]
 
@@ -356,6 +392,9 @@ class CryptographyService:
         Get version of the OpenSSL installed on the system
         :return: version of the OpenSSL as returned from the process
         """
+
+        Logger.debug("Function launched.")
+
         return self.__run_for_output(["version"]).decode("utf-8")
 
     def generate_crl(self, cert: Certificate, key: PrivateKey, index_file_path: str) -> str:
@@ -368,6 +407,9 @@ class CryptographyService:
         :param index_file_path: path to a file that contains the openssl index with all revoked certificates
         :return: CRL encoded in PEM format string
         """
+
+        Logger.debug("Function launched.")
+
         # openssl ca requires the .srl file to exists, therefore a dummy, unused file is created
         with TemporaryFile("serial.srl", "0") as serial_file, \
              TemporaryFile("crl.conf", CRL_CONFIG % (index_file_path, serial_file)) as config_file, \
@@ -392,6 +434,9 @@ class CryptographyService:
         :param der_ocsp_request: DER encoded OCSP Request
         :return: DER encoded OCSP Response
         """
+
+        Logger.debug("Function launched.")
+
         with TemporaryFile("certificate.pem", cert.pem_data) as ca_certificate, \
              TemporaryFile("private_key.pem", key.private_key) as key_file, \
              TemporaryFile("request.der", der_ocsp_request) as request_file:
@@ -413,8 +458,12 @@ class CryptographyException(Exception):
         self.message = message
 
     def __str__(self):
-        return f"""
+        # TODO check log is valid here
+        msg = f"""
         EXECUTABLE: {self.executable}
         ARGS: {self.args}
         MESSAGE: {self.message}
         """
+
+        Logger.error(msg)
+        return msg
diff --git a/src/services/key_service.py b/src/services/key_service.py
index e103891..14ba414 100644
--- a/src/services/key_service.py
+++ b/src/services/key_service.py
@@ -3,6 +3,7 @@ from injector import inject
 from src.dao.private_key_repository import PrivateKeyRepository
 from src.model.private_key import PrivateKey
 from src.services.cryptography import CryptographyService
+from src.utils.logger import Logger
 
 
 class KeyService:
@@ -18,6 +19,9 @@ class KeyService:
         :param passphrase: Passphrase to be used when encrypting the PK
         :return: An instance of the <PrivateKey> class representing the generated PK
         """
+
+        Logger.debug("Function launched.")
+
         # generate a new private key
         private_key_pem = self.cryptography_service.create_private_key(passphrase)
 
@@ -38,6 +42,9 @@ class KeyService:
         :param unique_id: ID of the PK to be found
         :return:An instance of the required PK or `None`
         """
+
+        Logger.debug("Function launched.")
+
         return self.private_key_repository.read(unique_id)
 
     def get_keys(self, unique_ids=None):
@@ -47,6 +54,9 @@ class KeyService:
         :param unique_ids: An array containing IDs of PKs to be fetched from the repository.
         :return: A list of instances of the PrivateKey class representing the PKs found
         """
+
+        Logger.debug("Function launched.")
+
         if unique_ids is None:
             return self.private_key_repository.read_all()
         else:
@@ -60,6 +70,9 @@ class KeyService:
         :param unique_id: ID of specific certificate to be deleted
         :return: `True` when the deletion was successful. `False` in other case
         """
+
+        Logger.debug("Function launched.")
+
         return self.private_key_repository.delete(unique_id)
 
     def get_public_key(self, private_key: PrivateKey):
@@ -68,5 +81,8 @@ class KeyService:
         :param private_key: private key from which a public key should be extracted
         :return: a string containing the extracted public key in PEM format
         """
+
+        Logger.debug("Function launched.")
+
         return self.cryptography_service.extract_public_key_from_private_key(private_key.private_key,
                                                                              private_key.password)
