From 681202be3b6152544c5d9fec3c4f5e81c1aca8b9 Mon Sep 17 00:00:00 2001 From: Vinogradov Anton Date: Wed, 21 Aug 2024 21:15:38 +0300 Subject: [PATCH] feat: logger connect to app --- application/backend/app/logger.py | 20 ++++++++++++++++++++ application/backend/app/settings.py | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 application/backend/app/logger.py diff --git a/application/backend/app/logger.py b/application/backend/app/logger.py new file mode 100644 index 0000000..a864991 --- /dev/null +++ b/application/backend/app/logger.py @@ -0,0 +1,20 @@ +import logging +import os + + +format = "%(asctime)s %(levelname)s: %(message)s" + + +def setupLoggerConfig(fileName): + logging.basicConfig( + level=logging.INFO, + format=format, + handlers=[ + logging.FileHandler(os.getenv("LOG_FILE_PATH") + "logs/" + fileName), + logging.StreamHandler(), + ], + ) + + +def setupLogger(): + setupLoggerConfig("info.log") \ No newline at end of file diff --git a/application/backend/app/settings.py b/application/backend/app/settings.py index 32a9fc8..b2292ab 100644 --- a/application/backend/app/settings.py +++ b/application/backend/app/settings.py @@ -13,10 +13,12 @@ from pathlib import Path import os import dotenv +from .logger import setupLogger # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent env = dotenv.load_dotenv() +setupLogger() # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/