diff --git a/src/settings/settings.py b/src/settings/settings.py index f50ecf2..6d859a5 100644 --- a/src/settings/settings.py +++ b/src/settings/settings.py @@ -1,6 +1,7 @@ import os from pathlib import Path +import sentry_sdk from cryptography.fernet import Fernet from dotenv import dotenv_values from sqlalchemy import create_engine @@ -54,3 +55,17 @@ def init_test_db(Base=Base, db_name="db_test.sqlite3"): session = Session() return session + + +SENTRY_DSN = env_vars.get("SENTRY_DSN") +if SENTRY_DSN: + sentry_sdk.init( + dsn=env_vars.get("SENTRY_DSN"), + # Set traces_sample_rate to 1.0 to capture 100% + # of transactions for performance monitoring. + traces_sample_rate=1.0, + # Set profiles_sample_rate to 1.0 to profile 100% + # of sampled transactions. + # We recommend adjusting this value in production. + profiles_sample_rate=1.0, + ) diff --git a/src/utils/fernet.py b/src/utils/fernet.py index 200fd27..5827285 100644 --- a/src/utils/fernet.py +++ b/src/utils/fernet.py @@ -1,3 +1,5 @@ +import logging + from ..settings.settings import fernet @@ -9,11 +11,15 @@ def encrypt(value: str) -> str: try: return fernet.encrypt(value.encode()).decode() except Exception as e: - print(f"encrypt error : {e}") + error_msg = f"encrypt error : {e}" + print(error_msg) + logging.exception(error_msg) @staticmethod def decrypt(value: str) -> str: try: return fernet.decrypt(value.encode()).decode() except Exception as e: - print(f"decrypt error : {e}") + error_msg = f"decrypt error : {e}" + print(error_msg) + logging.exception(error_msg) diff --git a/src/views/mixin.py b/src/views/mixin.py index d36044f..64f438f 100644 --- a/src/views/mixin.py +++ b/src/views/mixin.py @@ -1,6 +1,7 @@ import sys from rich.console import Console +import logging console = Console() @@ -15,6 +16,7 @@ def print_create_success(self, obj): success_msg = f"{self.name.title()} n°{obj.id} créé avec succès !\n" console.print(success_msg, style="bold green") + logging.info(success_msg) @classmethod def print_update_success(self, obj): @@ -23,11 +25,13 @@ def print_update_success(self, obj): success_msg = f"{self.name.title()} n°{obj.id} modifié avec succès !\n" console.print(success_msg, style="bold green") + logging.info(success_msg) @classmethod def print_delete_success(self, obj_id: int): success_msg = f"\n\n{self.name.title()} n°{obj_id} supprimé avec succès !\n\n" console.print(success_msg, style="bold green") + logging.info(success_msg) @classmethod def print_signature_success(self, session, obj): @@ -37,6 +41,7 @@ def print_signature_success(self, session, obj): ) console.print(success_msg1, style="bold green") + logging.info(success_msg1) success_msg2 = f"Vous pouvez maintenant créer un événement pour le {self.name} n°{obj.id}.\n"