diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..bfcf91b6 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5' +DEBUG=True +DB_HOST=db +DB_PORT=5432 +DB_NAME=term_db +DB_USER=sadilar +DB_PASSWORD=sadilar +LOGGING_FILE=logs/debug.log +LOGGING_HANDLERS_LEVEL=INFO +LOGGING_LOGGERS_LEVEL=INFO +LOGGING_LOGGERS_DJANGO_LEVEL=INFO diff --git a/.gitignore b/.gitignore index ec66bba8..5be98dc2 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ venv.bak/ app/static_files/ /app/documents/ app/media/ +/app/logging/ diff --git a/README.md b/README.md index d2f4ae1f..a5cf0372 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,16 @@ About the project: 3. Run `make run` to run the docker container 4. Run `make stop` to stop the docker container +## Production + ### Plugins installed #### Django Simple History https://django-simple-history.readthedocs.io/en/latest/ + +#### Basic setup for production + +### environment variables + +please use .env.example as example diff --git a/app/app/settings.py b/app/app/settings.py index f8680adf..898d5387 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -154,3 +154,52 @@ # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + + +if DEBUG: + LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "class": "logging.StreamHandler", + }, + }, + "root": { + "handlers": ["console"], + "level": "DEBUG", + }, + } +else: + LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "console": { + "class": "logging.StreamHandler", + }, + "file": { + "level": os.environ.get("LOGGING_HANDLERS_LEVEL", "WARNING"), + "class": "logging.FileHandler", + "filename": os.environ.get("LOGGING_FILE", "logging/debug.log"), + "formatter": "verbose", + }, + }, + "root": { + "handlers": ["console", "file"], + "level": os.environ.get("LOGGING_LOGGERS_LEVEL", "WARNING"), + }, + "loggers": { + "django": { + "handlers": ["file"], + "level": os.environ.get("LOGGING_LOGGERS_DJANGO_LEVEL", "WARNING"), + "propagate": True, + }, + }, + "formatters": { + "verbose": { + "format": "{asctime} {levelname} - {name} {module}.py (line: {lineno:d}). - {message}", + "style": "{", + }, + }, + }